Symfony2 bundle 未注册

标签 symfony registry bundle

我用应用程序/控制台创建了一个新包。尝试打印一个简单的 hello,以便我可以继续。我自动加载了命名空间,注册了包,创建了一个页面,但 Symfony 检测到一个异常:

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 

我还清除了缓存的 dev 文件夹。谁能帮我弄清楚出了什么问题。我以前也这样做过,这是我第一次遇到这个问题。与 bootstrap.php.cache 有关

谢谢!感谢所有的帮助。

代码:
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;
}

该包还在探查器中显示为事件包。

最佳答案

看起来引导缓存没有问题(第 634 行指向 Kernel::getBundles() 方法,这是抛出异常的原因),但以防万一,有一个脚本可以重建它:bin\build_bootstrap.php .缓存存在减少require()的数量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 服务器的用户是否可以读取您的包目录。我认为这会引发不同的错误,但值得检查!

关于Symfony2 bundle 未注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6284042/

相关文章:

mysql - 如何查看查询中的参数?

javascript - 我可以完全在 Controller 中创建 Symfony 表单提交吗?

java - 无法获取 Windows ProductId key ,但可以获取 ProductName key

c++ - RegLoadKey 给出错误代码 5(拒绝访问)

java - 需要帮助将第三方包装成一个包

android - adt eclipse 包 02-07-2014 更新

templates - Jade 兰 CMS : Introducing Magnolia tutorial not working with Magnolia CE and EE

php - 无法加载类型 "sonata_simple_formatter_type"

unit-testing - 在没有 Controller 的情况下测试电子邮件发送

c# - 是否有类似 Environment.SpecialFolder 的内容,但用于注册表路径