Symfony3错误添加新捆绑
问题描述:
我有一个捆绑,我创建并在另一个项目中工作。我复制src文件夹里面的文件夹捆绑,拷贝一些segurity参数,进口内config.yml的服务资源,并添加内AppKernel.php捆绑为Symfony3错误添加新捆绑
新LoginBundle \ LoginBundle()
当我做了一个$ php bin/console doctrine:schema:validate
它返回该错误
PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "LoginBundle" from namespace "LoginBundle".
Did you forget a "use" statement for another namespace? in {project}\app\AppKernel.php:18
Stack trace:
#0 {project}\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php(450): AppKernel->registerBundles()
#1 {project}\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php(116): Symfony\Component\HttpKernel\Kernel->initializeBundles()
#2 {project}\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php(69): Symfony\Component\HttpKernel\Kernel->boot()
#3 {project}\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php(125): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 {project}\bin\console(27): Symfo in {project}\app\AppKernel.php on line 18
编辑
AppKernel.php内容
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
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 LoginBundle\LoginBundle(),
new AppBundle\AppBundle(),
];
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;
}
public function getRootDir()
{
return __DIR__;
}
public function getCacheDir()
{
return dirname(__DIR__).'/var/cache/'.$this->getEnvironment();
}
public function getLogDir()
{
return dirname(__DIR__).'/var/logs';
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
}
}
而且这里去捆绑文件结构
而且这是LoginBundle.php
namespace LoginBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class LoginBundle extends Bundle
{
}
答
我的解决方案再次产生aoutoloaders像
php composer.phar dump-autoload
希望它可以帮助别人
答
我觉得在routing.yml中您必须添加
login:
resource: "@LoginBundle/Controller/"
type: annotation
prefix: /
+0
不错的尝试,但你能想到路由问题可能导致类没有发现异常吗? – Cerad
+0
没有解决,同样的错误 –
快,让我们AppKernel.php的内容。 另外,包的结构是怎样的? –
它出现在@MatkoĐipalo –
重复:https://*.com/questions/44946911/symfony3-classnotfoundexception-after-bundle-creation/44948820#44948820这里是一个提示。只需将一部分实际的错误消息粘贴到浏览器搜索栏即可。 – Cerad