到我的Symfony 3.3版本项目app/config/routing.yml
我放了:
AppBundle:
resource: '@AppBundle/Resources/config/routing.php'
prefix: /
type: 'php'
在src/AppBundle/Resources/config/routing.php
上,我放了以下内容:
use SymfonyComponentRoutingRouteCollection;
use SymfonyComponentRoutingRoute;
$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;
但是我收到以下错误:
自动加载器期望在文件"/home/pcmagas/Kwdikas/myblog/vendor/composer/."中定义类"AppBundle\Resources\config\routeting"。/../src/AppBundle/Resources/config/routeting.php"。找到文件,但类不在其中,类名或命名空间可能在/home/pcmagas/Kwdikas/myblog/app/config/services.yml 中有一个拼写错误(从"/home/pcmagas/Kwdikas/myblog/app/config/config.yml"导入)。
你知道研究员如何通过"外部"php文件加载路由吗?我的意思是,以与您通过 yml 加载通过 php 加载它们的路由相同的方式。
据我所知,根据: http://symfony.com/doc/current/routing.html 您可以使用 php 文件加载路由。
因为您的路由.php文件中没有命名空间。
你必须放在文件的开头:
namespace AppBundleResourcesconfig;