首页 文章

Symfony无法注册捆绑包

提问于
浏览
0

symproject/src/MyAppBundle/src/Bundle 我有一个包

该文件夹包含 MyAppBundle.php

<?php

    namespace MyCompany\Action\Provider\MyAppBundle\Bundle;

    use Symfony\Component\HttpKernel\Bundle\Bundle;

    class MyAppBundle extends Bundle
    {
    }

然后我在 App/Appkernel.php 注册:

public function registerBundles()
    {
        $bundles = [
            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 Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new AppBundle\AppBundle(),
            new MyCompany\Action\Provider\MyAppBundle\Bundle\MyAppbundle(),
        ];

        if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();

            if ('dev' === $this->getEnvironment()) {
                $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
                $bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
            }
        }

        return $bundles;
    }

完成此操作后,该网站将完全无法运行 . 日志说:

PHP致命错误:未捕获错误:在/var/www/html/symproject/app/AppKernel.php:20,nStack trace中找不到类'MyCompany \ Action \ Provider \ MyAppProvider \ Bundle \ MyAppBundle':\ n#0 / var / www / html / symproject / vendor / symfony / symfony / src / Symfony / Component / HttpKernel / Kernel.php(494):AppKernel-> registerBundles()\ n#1 / var / www / html / symproject / vendor / symfony / symfony / src / Symfony / Component / HttpKernel / Kernel.php(134):Symfony \ Component \ HttpKernel \ Kernel-> initializeBundles()\ n#2 / var / www / html / symproject / vendor / symfony / symfony / src / Symfony / Component / HttpKernel / Kernel.php(197):Symfony \ Component \ HttpKernel \ Kernel-> boot()\ n#3 /var/www/html/symproject/web/app.php(19):Symfony \ Component \ HttpKernel \ Kernel-> handle(对象(Symfony \ Component \ HttpFoundation \ Request))\ n#4 \ n在第20行的/var/www/html/symproject/app/AppKernel.php中抛出

1 回答

  • 0

    你已经将bundle类放到了

    symproject / src / MyAppBundle / src / Bundle

    文件夹,但名称空间是

    MyCompany \ Action \ Provider \ MyAppBundle \ Bundle

    它应该像命名空间一样

    App \ MyAppBundle \ Bundle

    并移动到文件夹

    symproject / src / MyAppBundle / Bundle

    或者您应该更改composer.json文件的自动加载部分以使用不同的类加载 .

    https://getcomposer.org/doc/01-basic-usage.md#autoloading

相关问题