Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top