如果你爲每個模塊做了一個真正的bundle方法,那麼完成你想要做的事情的最簡單方法就是使用帶有基於屬性路由的JMS Security-Extra bundle。
要將composer.json文件,補充一點: 「規定」:{ ... 「JMS /安全外束」: 「1.5 *」,
更新您的作曲家文件,
php composer.phar update
然後在你的BUNDLENAME /資源/配置/ routing.yml中的文件這樣做:
some_name:
type: annotation
resource: "@SomeBundle/Controller"
最後,在C每個動作ontroller,用@Route屬性裝飾它:
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
/**
* @Route("/SomeBundle/SomeController")
*/
class SomeController extends Controller {
/**
* @Route("someAction", name="myAction")
* @Method("GET") OR
* @Method({"GET", "POST"})
*/
public function someAction() {
}
}
JMS包中的一些其他屬性使事情變得非常好。例如,我對我的操作使用@Template屬性相當多。這意味着我不再需要做的:
public function recentListAction() {
...
return $this->render(
'AcmeArticleBundle:Article:recentList.html.twig',
array('articles' => $articles)
);
}
我可以簡單地做:
/**
* @Route("/Articles/List")
* @Template()
*/
public function recentListAction() {
...
return array('articles' => $articles);
}
而且只要我有一個資源/視圖/ ControllerName/recentList.html.twig文件,一切將自動爲我編織。
這可以幫助你:http://symfony.com/doc/current/cmf/book/routing.html#the-dynamicrouter – Brewal
嗯,我認爲這對我不是很有幫助:/ – Kofel
爲什麼你不能按照Symfony手冊的方式進行操作? – vascowhite