gpt4 book ai didi

symfony - 如何正确包含 bundle ?

转载 作者:行者123 更新时间:2023-12-02 11:45:05 26 4
gpt4 key购买 nike

我有这个错误:

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

这是我在 AppKernel.php 文件中的 registerBundles 函数:

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\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\AopBundle\JMSAopBundle(),
new JMS\DiExtraBundle\JMSDiExtraBundle($this),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
new Acme\OggyBundle\OggyBundle(),
);

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}

return $bundles;
}

我不明白...我包含 bundle new Acme\OggyBundle\OggyBundle(),但收到错误消息说我的 bundle 不包含在内!为什么?

日志文件:

[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse". [] [][2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\ChromePhpHandler::onKernelResponse". [] [][2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\CacheListener::onKernelResponse". [] [][2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse". [] [][2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelResponse". [] [][2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\Fragment\FragmentHandler::onKernelResponse". [] [][2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\Security\Http\RememberMe\ResponseListener::onKernelResponse". [] [][2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse". [] [][2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse". [] [][2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\StreamedResponseListener::onKernelResponse". [] [][2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.terminate" to listener "Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onKernelTerminate". [] []

最佳答案

如果您的 bundle 名称是 Acme OggyBundle ...那么您需要注册...

// ...
new Acme\OggyBundle\AcmeOggyBundle(),
// ...

...而不是

new Acme\OggyBundle\OggyBundle(),

AcmeOggyBundle 类必须位于文件中...

src/Acme/OggyBundle/AcmeOggyBundle.php

... 具有命名空间 Acme\OggyBundle 和类名 AcmeOggyBundle

<?php

namespace Acme\OggyBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class AcmeOggyBundle extends Bundle
{
}

如果您的包仍未加载...请确保 src/ 文件夹中的类正在自动加载

你的composer.json必须包含

    "autoload": {
"psr-0": { "": "src/" }
}

然后运行...

composer update -o

...以便重新生成由composer生成的vendor/autoload.php

关于symfony - 如何正确包含 bundle ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17080571/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com