dtwkt46424 2013-07-08 18:54
浏览 43

在autoload.php中使用registerNamespaces()

I use Symfony and I need to add couple bundles in my autoload.php file, which is in .../app/ folder. So, I basically wrote this:

 <?php
// [snip]

use Doctrine\Common\Annotations\AnnotationRegistry;

    $loader->registerNamespaces(array(
        'Behat\BehatBundle' => '/var/www/testsuite.behat/vendor',
        'Behat\Behat'       => '/var/www/testsuite.behat/vendor/Behat/Behat/src',
        'Behat\Gherkin'     => '/var/www/testsuite.behat/vendor/Behat/Gherkin/src',
        'Behat\Mink'        => '/var/www/testsuite.behat/vendor/Behat/Mink/src',
        'Behat\MinkBundle'  => '/var/www/testsuite.behat/vendor',
        'Goutte'            => '/var/www/testsuite.behat/vendor/Goutte/src',
        'Zend'              => '/var/www/testsuite.behat/vendor/Zend/library',
        'Behat\SahiClient'  => '/var/www/testsuite.behat/vendor/Behat/SahiClient/src',
        'Buzz'              => '/var/www/testsuite.behat/vendor/Buzz/lib'
    ));
    $loader->register();

And when I run php app/console it shows me the error:

PHP Notice:  Undefined variable: loader in /var/www/~/app/autoload.php on line 6
PHP Fatal error:  Call to a member function registerNamespaces() on a non-object in /var/www/~/app/autoload.php on line 6

where "~" is my project's name.

Please, help me with this problem.

  • 写回答

1条回答 默认 最新

  • dsiuz86842 2013-07-08 21:42
    关注

    Considering you have version 2.1 or higher, this isn't needed anymore. 3th party bundles should be installed via composer, which will take care of the autoloading. This step is only needed for 2.0 versions, as those use the old vendor script created by symfony.

    If you, for some reason, still need to register some namespaces, you should do that in your composer.json file:

    {
        ...
        "autoload": {
            "psr-0": {
                "My\\Namespace": "path/to/me"
            }
        }
    }
    

    More information: http://getcomposer.org/doc/04-schema.md#psr-0

    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)