路由设置相关问题
洪老您好,我今天调试了一天路由的配置,有几个问题还是没有想明白,请洪老解惑。上代码:
第一个问题:
#app/config/routing.yml中路由配置 custom: resource: @CustomSiteBundle/Controller/ type: annotation
#src/Custom/SiteBundle/Controller/DefaultController.php namespace Custom\SiteBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; // these import the "@Route" and "@Template" annotations use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; class DefaultController extends Controller { /** * @Route("/", name="_demo") * @Template() */ public function indexAction() { return array(); } }
此时可以正常访问该路由:http://localhost/app.php,但是我新建一个Controller:
#src/Custom/SiteBundle/Controller/CommunalController.php namespace Site\HomeBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; // these import the "@Route" and "@Template" annotations use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; /** * @Route("/communal") */ class CommunalController extends Controller { /** * @Route("/navgate") * @Template() */ public function naygateAction() { return array(); } /** * @Route("/sidebar") * @Template() */ public function sideBarAction() { return array(); } /** * @Route("/footer") * @Template() */ public function footerAction() { return array(); } }
此时访问/communal下的任何一个方法都报404,http://localhost/app_dev.php/communal
查看官方文档有:
Including External Routing Resources
All routes are loaded via a single configuration file - usually app/config/routing.yml (see Creating Routes above). However, if you use routing annotations, you'll need to point the router to the controllers with the annotations. This can be done by "importing" directories into the routing configuration:
但不知我这错在那块?
还有app/config/routing.yml中custom指的是什么?和@Route("/", name="_demo")中的name是什么关系?
第二个问题:
#修改app/config/routing.yml custom: resource: "@CustomSiteBundle/Resources/config/routing.yml"
#CustomSiteBundle/Resources/config/routing.yml custom: resource: @CustomSiteBundle/Controller/ type: annotation
修改后访问http://localhost/app_dev.php,404
这块又是为什么,我只是换了位置?
请洪老答疑,我觉得路由这块洪老一笔带过,尤其是app/config/routing.yml与其他bundle的routing.yml之间关系讲的很简单,难道也是伏笔?