How to install PHPExcel in symfony2.5 using netbeans - symfony

I am facing problem with PHPExcel installation in symfony2.5.
I have downloaded PHPExcel directory from GitHub and I dont know the configuration steps.
as I am beginner I would need complete steps to understand the complete installation process,
Please help me regarding this,
Thanks in advance.

You can add it to your composer.json or require it with composer (php composer.phar require "phpoffice/phpexcel:1.8.0) like most other php packages which will then add it to the class loader meaning you can just use it like \PHPExcel_....
The available packages for it are on packagist.
If you are wanting to use the classes from a version that you have downloaded you can add them to your src directory and they will be autoloaded there through the default autoload setting.
"autoload": {
"psr-0": { "": "src/"}
},

Related

Use Composer with Wordpress

Im trying to setup a pleasant way of working with wordpress and its plugins using composer. My question will be quite broad. How would you do it?
What i want is basically so it installs wordpress (which is now doing), but the plugins i specify get installed in a folder named "vendor" and not in the "plugins" folder. Why is that?
Here is my composer.json.
{
"name": "name",
"description": "name Wordpress",
"repositories":[
{
"type":"composer",
"url":"https://wpackagist.org"
}
],
"require": {
"timber/timber": "^1.3",
"johnpbloch/wordpress-core-installer": "^0.2.1",
"johnpbloch/wordpress": "^4.4"
},
"extra": {
"installer-paths": {
"wp-content/plugins/{$name}/": ["type:wordpress-plugin"],
"wp-content/themes/{$name}/" : ["type:wordpress-theme"]
},
"wordpress-install-dir": "wp"
}
}
I'm pretty new to this idea of using composer for package management inside WP. But I found this interesting, so I looked into it.
The installation path is specific to the plugin. Also look for wpackagist-plugin vendor name. Others will probably not put code inside the wp folder.
If you require "wpackagist-plugin/advanced-custom-fields": "^4.4" for example it is installed inside the plugins folder, as desired. The vendor prefix ('wpackagist-plugin') is important, I believe, as the packages in their search have no prefixes.
Quick solution
Try using "wpackagist-plugin/timber-library": "^1.3"
It is placed into the plugins folder nicely and comes with all it's dependencies inside the plugin folder.
Some more explanation
timber/timber is actually pulled from packagist.org (https://packagist.org/packages/timber/timber) instead of wpackagist.org.
On wpackagist.org you can find timber-library which is the packaged equivalent (includes composer autoloader and other deps).
This recipe for paths control (for plugin developers) says that:
To make use of it your extension's composer.json should contain:
"type" : "wordpress-plugin",
After you installed your packages using composer install you'll see, that the package inside of vendor/timber/timber doesn't have that type.
In fact there's an older WordPress plugin called timber, that's stuck on version 0.8. It's succeeded by timber-library.
Using "timber/timber": "^1.3" as from packagist.org
If you want to use timber as pulled from packagist.org you can do so, if you place the following line at the top of your wp-config.php:
require __DIR__ . '/wp-content/vendor/autoload.php';
Then you'll have to deploy both, the vendor and the wp folder.
There's also a discussion on GitHub about how to use vendor libraries in WP projects.
Hope you get along with that info.

How to install KnpSnappyBundle in Symfony 2.8?

I just need to install a bundle which help me to generate PDF files, but I don't know how to start to install, I don't understand the documentation, the KnpSnappyBundle's documentation says to install with composer to make:
{
"require": {
"knplabs/knp-snappy-bundle": "~1.4"
}
}
but I don't know where put such code. Nevertheless I am open to other bundle in which I can create PDF files, and please explain me step by step how to install it, I am a beginner in Symfony.
From a command line in your Symfony project folder you can run:
composer require knplabs/knp-snappy-bundle "~1.4"
And that will install the bundle for you.
I have done like below after adding it to composer.json under require
"require": {
"knplabs/knp-snappy-bundle": "dev-master"
}
After adding above run "composer update"

Symfony 2 - How to determine the namespace and Bundle name for autoload.php & Appkernel.php

I'm very new to symfony2 and I cannot find this info:
To register a bundle located in my vendor dir, how to determine the namespace and Bundle name for autoload.php & Appkernel.php?
For example, I have downloaded Luiggio's PHPExcel Bundle. I have place it in vendorDir/ExcelBundle/
Where content is:
namespace Liuggio\ExcelBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class LiuggioExcelBundle extends Bundle
{
}
What lines should I put in Appkernel and namespace.php?
This and this does not work:
new Liuggio\ExcelBundle\LiuggioExcelBundle()
//'Liuggio\\ExcelBundle' => array($vendorDir. '/PHPExcel'),
I cannot use composer or github repo at all, too many proxies and restrictions where I am.
You shouldn't place bundles in your vendor directory manually. Let Composer do this for you. Not only does Composer know where vendor libraries / bundles should be located, it also adds them to your autoload files and performs some other automated tasks.
To tell Composer which libraries are required, you should add them to your composer.json:
"require" : {
(...)
"liuggio/ExcelBundle": "~2.0"
},
Next, using the command line, run the composer update command:
$ php composer.phar update
(if you don't have a file composer.phar in your project directory, but you have Composer installed globally instead, use the following:)
$ composer update
This will tell Composer to download the required dependencies, update the autoload script, etc, all automatically. When it's finished, you're ready to go.
If you can't use Composer on your server, then run it locally before you upload your files (although I strongly recommend moving to a server that does allow you to use Composer).
The line you're trying to add to AppKernel.php is correct, however it only works after running Composer (or you'd indeed have to download the files and update the autoloader manually, but I'd strongly recommend against that).
Edit
If you really can't use Composer, do the following:
Place the files of ExcelBundle in the following directory:
vendor/liuggio/ExcelBundle/Liuggio/ExcelBundle
Your line in AppKernel.php was already correct.
Add this line to autoload_namespaces.php:
'Liuggio\\ExcelBundle' => array($vendorDir . '/liuggio/ExcelBundle'),
Last but not least, complain to your system administrator that he's making your work impossible with his stupid security measures.
new Liuggio\ExcelBundle\LiuggioExcelBundle(),
in AppKernel should be working fine.
This is the namespace of the LuiggioExcelBundle class + the class name. Look how your bundles are loaded, its the same.
What's your error?
You say vendorDir/ExcelBundle/ but its vendor/ExcelBundle right?
And what do you mean by namespace.php? :o
https://github.com/liuggio/ExcelBundle ==> there readme is rly easy to understand, it should help you.
For your "proxies and restriction", composer is a powerful tool, I can help you to use it. Download this soft, the free version is enough http://www.frozenway.com/ (if you cant read french, the 1st input in the header is to translate the website, English is Anglais) With this, you wont have any ports restriction.

Symfony 2, adding vendor library (PHPExcel etc.)

In my symfony 2.2 app I wanted to use PHPExcel library. So I downloaded it, and copied contents of Classes library to /vendor/phpexcel directory:
vendor/
phpexcel/
PHPExcel/
PHPExcel.php
After that I added the following to app/autoload.php directly below $loader = require ... line:
$loader = require __DIR__.'/../vendor/autoload.php';
//The following was added
$loader->registerPrefixes(array(
'PHPExcel' => __DIR__ . '/../vendor/phpexcel'
));
// intl
...
Now if I browse to my web app, it returns HTTP Error 500 (Internal Server Error). I read the following post, but wasn't able to solve the problem:
How to use PHPExcel correctly with Symfony 2
Can someone help me correct this?
You should never manually download something and put it in the vendor directory. Composer manages the vendor directory, and hence it should be save to delete this directory and run composer install again. The vendor directory also is excluded from Git by default.
To install PHPExcel using composer, add it to composer.json:
"require": {
...
"phpexcel/phpexcel": "1.7.*"
}
When installed with Composer, you should not need to worry about the autoloading either.
I installed https://github.com/liuggio/ExcelBundle for PHPExcel. Bundle includes PHPExcel (addes related links to composer). You can easily use PHPExcel without wondering what the bundle says. Call new \PHPExcel(); then you move. I hope this bundle helps.
Composer seems to have a problem with SELinux. See this. Though not recommended, setting SELinux to permissive can be a workaraound.

Symfony 2.1 own vendor library

I want to put some code that I shall use in different projects outside the app's bundles. I put it in a new folder in the vendor folder but I can't included in the project. Which are the steps?
Should I follow a special structure of folder and namespaces
How do I included in my project.
On Google I found a lot of ambiguous answers. I tried also this but it did not work.
You need to get your library loaded. You do this by telling composer where to find your library.
The best thing would be to set up a git repository for this source code and then use composer to load it, keep it up to date and include it into the autoloader. You may need to get used to composer to do this, but as composer is getting the default dependency management tool for php, the time is not wasted. You can find the docs here: http://getcomposer.org/doc/
If you don't want to do this, you can add a new src code folder to composer. Let's say your folder structure is like this:
symfony2/
vendor/
yourlibrary/
Bla/
Blub/
MyClass.php
First, the MyClass.php should have the namespace Bla/Blub defined. Else Then you can add your library like this to the composer.json file:
"autoload": {
"psr-0": {
"": "src/",
"Bla": "vendor/yourlibrary/"
}
}
You already have autoload defined, so you need to overwrite it!
If your library doesn't have namespaces, you can define composer to load it nonetheless. I am not using this, so I can just link the docs where you can read it up: http://getcomposer.org/doc/04-schema.md#autoload

Resources