2011-06-08 147 views
5

我使用app/console创建了一个新软件包。试着打印一个简单的问候,让我可以继续前进。我自动加载的命名空间,注册了捆绑,创建了一个页面,但Symfony的检测到异常:Symfony2软件包未注册

Bundle "PageBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() function of your AppKernel.php file? 

可是我已经这样做了。

日志显示:

[2011-06-08 23:41:56] request.CRITICAL: InvalidArgumentException: Bundle "PageBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() function of your AppKernel.php file? (uncaught exception) at /Applications/MAMP/htdocs/Symfony/app/bootstrap.php.cache line 634 

我也被清除缓存文件夹开发。任何人都可以帮我弄清楚什么是错的。我之前做过这件事,这是我第一次遇到这个问题。与bootstrap.php.cache有关的东西

谢谢!感谢所有的帮助。

CODE:

public function registerBundles() 
{ 
    $bundles = array(
     new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), 
     new Symfony\Bundle\SecurityBundle\SecurityBundle(), 
     new Symfony\Bundle\TwigBundle\TwigBundle(), 
     new Symfony\Bundle\MonologBundle\MonologBundle(), 
     new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(), 
     new Symfony\Bundle\DoctrineBundle\DoctrineBundle(), 
     new Symfony\Bundle\AsseticBundle\AsseticBundle(), 
     new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), 
     new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(), 
    ); 

    if (in_array($this->getEnvironment(), array('dev', 'test'))) { 
     $bundles[] = new Webmuch\PageBundle\WebmuchPageBundle(); 
     $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); 
     $bundles[] = new Symfony\Bundle\WebConfiguratorBundle\SymfonyWebConfiguratorBundle(); 
    } 

    return $bundles; 
} 

束还示出了如在分析器的有源束。

+0

我删除了缓存和引导文件。然后从控制台重建引导文件。还是一样的错误。我错过了什么? – Aayush 2011-06-08 19:25:34

+2

向我们展示您的registerBundles()函数。 – 2011-06-08 19:29:05

+0

我已将它添加到问题中。谢谢! – Aayush 2011-06-09 16:29:55

回答

5

它看起来不像引导缓存(第634行指向Kernel::getBundles()方法,这是抛出异常)的问题,但以防万一,有一个脚本会重建它:bin\build_bootstrap.php。缓存的存在是为了减少Symfony需要加载核心Symfony类所需的数量,只要你使用其中一个测试版,就不太可能存在真正的错误。

听起来这可能是一个命名问题:您的错误抱怨缺少PageBundle,但根据您的内核,应该将该包称为WebmuchPageBundle。你有没有在你的routing_dev.yml中正确引用它?一个例子路由设置是:

page: 
    resource: "@WebmuchPageBundle/Controller/DefaultController.php" 
    type:  annotation 

因为你只定义捆绑的开发&测试环境中,你应该使用routing_dev.yml而不是routing.yml

接下来,检查捆绑类是否正确命名。你应该有一个文件在您的套装(如src/Webmuch/PageBundle/WebmuchPageBundle.php)具有以下内容的根:

namespace Webmuch\PageBundle; 
use Symfony\Component\HttpKernel\Bundle\Bundle; 

class WebmuchPageBundle extends Bundle 
{ 
} 

哦,显然检查Web服务器的用户可以读取你的包目录。我认为抛出一个不同的错误,但它值得检查!

3

我之前有过这个错误。检查你的路线! 可能介于你有这样的台词:

webmuch_page_hello_world: 
    pattern: /hello 
    defaults: { _controller: PageBundle:Default:hello } 

有“PageBundle”是不正确的。你应该使用“WebmuchPageBundle”。所以像这样使用它:WebmuchPageBundle:默认:你好