Symfony的3.3:内包加载路由使用PHP文件需要

要我Symfony的版本在app/config/routing.yml文件3.3的项目,我已经把:Symfony的3.3:内包加载路由使用PHP文件需要

AppBundle: 

resource: '@AppBundle/Resources/config/routing.php'

prefix:/

type: 'php'

而且在src/AppBundle/Resources/config/routing.php我已经把以下内容:

use Symfony\Component\Routing\RouteCollection; 

use Symfony\Component\Routing\Route;

$collection = new RouteCollection();

$collection->add('blog_list', new Route('/blog', array(

'_controller' => 'AppBundle:Blog:list',

)));

$collection->add('blog_show', new Route('/blog/{slug}', array(

'_controller' => 'AppBundle:Blog:show',

)));

return $collection;

,但我得到了以下错误:

The autoloader expected class "AppBundle\Resources\config\routing" to be defined in file "/home/pcmagas/Kwdikas/myblog/vendor/composer/../../src/AppBundle/Resources/config/routing.php". The file was found but the class was not in it, the class name or namespace probably has a typo in /home/pcmagas/Kwdikas/myblog/app/config/services.yml (which is being imported from "/home/pcmagas/Kwdikas/myblog/app/config/config.yml").

你知道伙伴们如何通过“外部”php文件加载路线吗?我的意思是,通过yml加载通过php加载它们的路径。

正如我所知,根据:http://symfony.com/doc/current/routing.html你可以使用PHP文件来加载路由。

回答:

可能是因为您的routing.php文件中没有命名空间。

你必须把在文件的开头:

namespace AppBundle\Resources\config; 

以上是 Symfony的3.3:内包加载路由使用PHP文件需要 的全部内容, 来源链接: utcz.com/qa/263723.html

回到顶部