要我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文件來加載路由。
Symfony的版本?你有什麼看起來應該工作。 – Cerad
它在標題 –
上寫着我忘了我已經回答了這個問題:https://stackoverflow.com/questions/46099282/symfony-using-yaml-and-php-routing/46100447#46100447 – Cerad