Add phpexcel to my project - phpexcel

I need to generate Excel files, I did a search and phpexcel seems to be good and stable. I'd like to know:
* how to integrate it into my project given that it's a symfony2.0 project
* if I can do all what I do normally on excel file through this php library (cells colors, adding lists ...)
Thanks,

If you are using composer, and since PHPExcel is registered with Packagist, then this is simply a matter of adding PHPExcel to your composer.json config, for example:
"require": {
"php": ">=5.3.3",
"symfony/symfony": "~2.4",
"doctrine/orm": "~2.2,>=2.2.3",
...
"phpoffice/phpexcel": "~1.8.0",
This is from a Symfony 2.4 configuration, but should work equally well for any version of Symfony.
Run $ php composer.phar update to grab the package and it should then be autoloaded into your project. You can then use PHPExcel immediately, say in a controller:
<?php
namespace SomeProject\SomeBundle\Controller;
use PHPExcel;
Or just reference \PHPExcel directly from within your code.
Update:
Note that composer found it's way into Symfony from around version 2.0.4, and was used as an alternative to the old deps and deps.lock files until the deps approach was deprecated from 2.1.
If you're still using deps, you can append this to your deps file:
[PHPExcel]
git=git://github.com/PHPOffice/PHPExcel.git
target=phpexcel
and run php bin/vendors install. This will put the PHPExcel in vendors/phpexcel.
Register PHPExcel with the registerPrefixes array in app/autoload.php and it should be available to your project as described above.
$loader->registerPrefixes(array(
'Twig_Extensions_' => __DIR__.'/../vendor/twig-extensions/lib',
'Twig_' => __DIR__.'/../vendor/twig/lib',
'PHPExcel' => __DIR__.'/../vendor/phpexcel/Classes'
));

Related

Can't load fixtures in other environment

In my composer.json, I added doctrine-fixtures-bundle in require-dev as recommended in the documentation
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3",
...
},
I created a new symfony benchmark environment, but I cannot access the fixtures :
$ APP_ENV=benchmark php bin/console doctrine:fixtures:load
You may be looking for a command provided by the "DoctrineFixturesBundle" which is currently not installed. Try running "composer require doctrine/doctrine-fixtures-bundle --dev"
Fixtures is available in dev. How to make it also accessible in benchmark environment ?
I don't think adding fixtures in require to composer.json is a good idea : it's not safe.
You should not define this library as a dev dependency then. Move it from the require-dev to the require section and reinstall vendors with Composer.
It's "not safe" as in you could potentially load the fixtures on production and erase your database. If you are afraid you could do so, you can load this bundle for the benchmark environment only, eg.:
// config/bundles.php
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'benchmark' => true],

HWIOauthbundle with FOSUserbundle Integration error

Attempted to load class "Curl" from namespace "Buzz\Client". Did you
forget a "use" statement for another namespace? 500 Internal Server
Error - ClassNotFoundException
in app/cache/dev/appDevDebugProjectContainer.php at line 1809 -
protected function getHwiOauth_HttpClientService()
{
$this->services['hwi_oauth.http_client'] = $instance = new \Buzz\Client\Curl();
$instance->setVerifyPeer(false);
$instance->setTimeout(10);
When you asking a question please specify your operating system and versions of frameworks you are using (e.g. symfony 2). Here is an answer for windows and symfony2
1) Delete manually added folders
2) If you don't have composer installed, install it
For windows
For other read this
2) Install HWIOAuthBundle
HWIOAuthBundle readme.md
option i) Using composer
Open the symfony project directory where composer.json resides.
Open command prompt (In Windows: Shift key + Right click => open command window here)
Run this
composer require hwi/oauth-bundle
OR
option ii) Add dependencies to your composer.json (not recomended)
"require": {
// other dependencies will be here //
"hwi/oauth-bundle": "^0.4.0",
"friendsofsymfony/user-bundle": "^1.3"
}
then execute following command
composer install

Undefined method registerNamespaces() symfony2

I'm following this FOSTwitterBundle documentation:
https://github.com/FriendsOfSymfony/FOSTwitterBundle
I did it all step by step, but when I access my site, i get this error:
Fatal error: Call to undefined method Composer\Autoload\ClassLoader::registerNamespaces() in C:\xampp\htdocs\Symfony\app\autoload.php on line 16
My autoload.php is like this:
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
$loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
$loader->registerNamespaces(array(
// ...
'FOS' => __DIR__.'/../vendor/bundles',
// ...
));
return $loader;
What should I do?
for symfony 2.*
replace this
$loader->add('FOS' => __DIR__.'/../vendor/bundles');
with
$loader->add('FOS', __DIR__.'/../vendor/bundles');
The basic problem is that the installation directions are for Symfony 2.0. You are using S2.1. I have not poked around in the twitter bundle. Hard to say if it will even run under 2.1. Installing it via git submodule instead of using composer seems strange.
Try starting over and adding: "friendsofsymfony/twitter-bundle": "dev-master" to your composer.json and doing an install. This should bring down the packages and take care of autoloading for you.
Otherwise, replace:
$loader->registerNamespaces(array('FOS' => __DIR__.'/../vendor/bundles'));
with
$loader->add('FOS' => __DIR__.'/../vendor/bundles');
S2.1 uses a different class loader than S2.0 with a different interface. It will at least get you past the error message.
But again, try the composer route first and then maybe submit a patch to the project to update the readme file.
OAuth?
I used https://github.com/hwi/HWIOAuthBundle no long time ago.
How to integrate with FOSUB: https://github.com/hwi/HWIOAuthBundle/issues/81

Installing LiipImagineBundle for Symfony 2.1 using Composer

LiipImagineBundle doesn't seem to have instructions for installing itself using composer (github page) so I added
"liip/imagine-bundle": "*",
to my composer.json and updated. Everything went fine until I tried to register the bundle in appKernel.php with the line
new Liip\ImagineBundle\LiipImagineBundle(),
Php gives the error
Fatal error: Class 'Liip\ImagineBundle\LiipImagineBundle' not found in C:\xampp\htdocs\xxxx\Symfony\app\AppKernel.php on line 24
As far as I can see LiipImagineBundle is in the right place in the vendors folder. Anyone have any idea where I'm going wrong? Thanks in advance.
*Edit I should add I'm using symfony 2.1
I had to change the line in composer to this:
"liip/imagine-bundle": "*#dev"
notice the #dev at the end. This tell composer that I am willing to accept "dev" stability
I contacted the developer of the bundle and found that there is a vendor/composer/autoload_namespaces.php where you can manually add entries and the bundle wasn't there.
This guide was helpful: Composer Namespaces in 5 Minutes
I'm using Symfony 2.1.4-DEV and including "liip/imagine-bundle": "*" on the composer.json and updating it works
Did you registered Namespace in autoload.php and registered Bundle in AppKernel.php? If not the class will be not avialable to use until registration there.
As the documentation says:
<?php
// app/autoload.php
$loader->registerNamespaces(array(
// ...
'Imagine' => __DIR__.'/../vendor/imagine/lib',
'Liip' => __DIR__.'/../vendor/bundles',
));
And
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Liip\ImagineBundle\LiipImagineBundle(),
);
}
Update
Run composer update it will regenerate your bootstrap files. tell me if any luck with this.

How to install a Symfony 2.0 Bundle from Zip file

I tried installing the FixturesBundle as described in http://symfony.com/doc/2.0/bundles/DoctrineFixturesBundle/index.html but my proxy wont let me out.
So I went to https://github.com/doctrine/data-fixtures and download a zip from the latest commit.
I unzipped into the vendor directory and renamed it to doctrine-fixures. I edited the autoload.php and AppKernel.php files as described in the tutorial.
When I run:
php app\console doctrine:fixtures:load
I get the following message:
PHP Fatal error: Class 'Symfony\Bundle\DoctrineFixturesBundle\DoctrineFixturesB
undle' not found in C:\NetbeansProjects\route_rest_service\app\AppKernel.php on
line 20
Fatal error: Class 'Symfony\Bundle\DoctrineFixturesBundle\DoctrineFixturesBundle
' not found in C:\NetbeansProjects\route_rest_service\app\AppKernel.php on line
20
Is there a way to run the installation of bundle pointing it to a zip file?
I´m running Symfony 2.0.9 on Windows 7.
Seems like the doctrine bundle has been moved outside of Symfony scope back to Doctrine.
Please, use https://github.com/doctrine/DoctrineFixturesBundle
I had the same problem and this is how i successfully solved it. I started to download this files data-fixtures and DoctrineFixturesBundle, unzipped both into /vendor/doctrine and created this folder structure:
vendor
- doctrine
- doctrine-fixtures-bundle
- Doctrine
- Bundle
- FixturesBundle
DoctrineFixturesBundle.php
..other files...
vendor
- doctrine
- data-fixtures
- lib
- test
composer.json
..other files...
Then i edited the AppKernel.php and added
public function registerBundles(){
.....
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
.....
}
Edited the composer.json located in the root of the project and added this 2 lines:
"Doctrine\\Bundle\\FixturesBundle": "vendor/doctrine/doctrine-fixtures-bundle",
"Doctrine\\Common\\DataFixtures": "vendor/doctrine/data-fixtures/lib"
Mine, now look like this:
{
"autoload": {
"psr-0": {
"": "src/",
"Doctrine\\Bundle\\FixturesBundle": "vendor/doctrine/doctrine-fixtures-bundle",
"Doctrine\\Common\\DataFixtures": "vendor/doctrine/data-fixtures/lib"
}
}
}
afterwards execute composer dump-autoload -o to recreate the classmap. All this was thanks to the users Wouter J and nifr that answered my question How to install DoctrineFixturesBundle offline
Happy coding!
Yes, it's true that Doctrine is being moved away from the Symfony namespace (see here).
So if you're using the Symfony standard distribution you download from the website (without using git), and you want to have the FixturesBundle installed manually, you have to download the doctrine-fixtures library from here, extract the zip into
YourProject/vendor/doctrine-fixtures
Download the FixturesBundle from here, and extract it in
YourProject/vendor/bundles/Doctrine/Bundle/FixturesBundle
Then you have to register the library's namespace, do it by adding
'Doctrine\\\\Common\\\\DataFixtures' => \__DIR\__.'/../vendor/doctrine-fixtures/lib',
in your autoload.php.
In addition, you'll have to register the Doctrine's namespace, because some part of your application will be using the DoctrineBundle shipped from the Symfony namespace, but the new downloaded FixturesBundle will be using the new Doctrine's namespace, so to make it work, in your autoload.php add the following line (taking care you do it before the Doctrine namespace, remember that more specific rules go first!)
'Doctrine\\\\Bundle' => \__DIR\__.'/../vendor/bundles',
So all you have to do now is to register the new bundle in your AppKernel.php writing
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),

Resources