2013-09-26 30 views
0

在Symfony1我可以:Get請求參數中嵌入控制器

blog: 
    url: /blog/slug 
    param: { module: blog, action: index } 

和在動作/控制器I可以得到團狀:$請求 - >的getParameter( '蛞蝓');

在Symfony2中:

blog: 
    path:  /blog/{slug} 
    defaults: { _controller: AcmeBlogBundle:Blog:show } 

和我創建 「組件」 一樣Symfony1 - http://symfony.com/doc/current/book/templating.html#templating-embedding-controller

我怎樣才能得到嵌入控制器塞?我試過了:

$request->query->get('foo'); 
$request->request->get('bar'); 

但是這仍然返回null。在AcmeBlogBu​​ndle:博客:show controller工作正常。

+0

顯示你的代碼,您嵌入的內容。 –

回答

2

參數轉換器將使用來自路徑的字符串填充參數。所以這裏是你的方法的樣子。

class BlogController extends Controller { 
    public function showAction($slug) { 
     // $slug will contain the value of the string from the route 
    } 
} 

所以,如果你想嵌入到樹枝模板它看起來像這樣的:

{{ render(controller('AcmeBlogBundle:Blog:show', {'slug': 'this-is-the-slug' })) }} 

或從另一個控制器

$this->render('AcmeBlogBundle:Blog:show.html.twig', array('slug' => 'this-is-the-slug')); 
+0

但我想嵌入控制器,而不是在博客控制器slug嵌入式控制器 – claudio3949

+1

它工作完全相同的嵌入式控制器,你的路由定義和你的方法保持完全一樣,唯一的區別是,你正在生成請求這個控制器從任一另一個控制器或樹枝模板。 –