第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

路由設(shè)置相關(guān)問題

洪老您好,我今天調(diào)試了一天路由的配置,有幾個(gè)問題還是沒有想明白,請洪老解惑。上代碼:

第一個(gè)問題:

#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();
????}
}

此時(shí)可以正常訪問該路由:http://localhost/app.php,但是我新建一個(gè)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();
????}
}

此時(shí)訪問/communal下的任何一個(gè)方法都報(bào)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:

但不知我這錯(cuò)在那塊?

還有app/config/routing.yml中custom指的是什么?和@Route("/", name="_demo")中的name是什么關(guān)系?


第二個(gè)問題:

#修改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之間關(guān)系講的很簡單,難道也是伏筆?

正在回答

3 回答

1.其實(shí)你不用試來試去,每個(gè)action最終的訪問路徑可以通過命令行工具查看,app/console router:debug

2.我不建議把yml里的key寫成一樣的,也就是說你第一個(gè)custom和第二個(gè)custom最好換成兩個(gè)不重復(fù)的名字。判斷routing是否設(shè)置成功,配置是否載入成功等等,最好的辦法還是通過上面一條中說到的router:debug去分析,如果這個(gè)命令中出現(xiàn)了Path為/的路由,那么你的http://localhost/app_dev.php肯定是可以打開的,如果沒有出現(xiàn),則必定是404。


2 回復(fù) 有任何疑惑可以回復(fù)我~
#1

sfg 提問者

非常感謝!
2015-01-28 回復(fù) 有任何疑惑可以回復(fù)我~

補(bǔ)充一點(diǎn),在routing.yml中定義路由和在annotation中定義路由是二選其一的兩種定義路由的方式,所以雖然Route里可以定義name,但實(shí)際操作上并不會(huì)沖突。

0 回復(fù) 有任何疑惑可以回復(fù)我~
還有app/config/routing.yml中custom指的是什么?和@Route("/",?name="_demo")中的name是什么關(guān)系?

custom就是指這個(gè)路由的名字,將來在模板中或者在controller中如果要生成指向某一個(gè)路由的鏈接,你就會(huì)用到這個(gè)名字。

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

路由設(shè)置相關(guān)問題

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)