簡體   English   中英

symfony - 如何進行路由

[英]symfony - how to do routing

我需要 symfony 的幫助,如何進行路由並將頁面添加到完成的項目中,這是我添加新路由的地方:src/BlogBu​​ndle/Resources/config/routing_news.yml 這里是代碼:

reset:
    path: / reset_mail
    defaults: {_controller: BlogBundle: Page: reset_mail}

然后我在控制器中添加:src/BlogBu​​ndle/Controller/PageController.php 代碼:

public function reset_mail(Request $request)
{
    $pageRepository = $this->getDoctrine()->getRepository('AdminBundle: reset_mail');
    $page = $pageRepository->findOneBy([
        'path' => 'page / reset_mail'
    ]);

    return $this->render('BlogBundle: Page: reset.html.twig', [
        'title' => $page->getTitle()
    ]);
}

好吧,我在 src/BlogBu​​ndle/Resources/views/Page 中創建了文件:reset.html.twig。 所以這就是我做錯的地方,因為當我去這個/頁面/reset_mail 時,什么也沒有發生。 我做錯了什么,如何做對?

您應該為路由使用注釋。

https://symfony.com/doc/current/routing.html

這是一個很好的做法( https://symfony.com/doc/current/best_practices.html#don-t-use-annotations-to-configure-the-controller-template )。

使用注釋真的很簡單,而且更好。

希望這會很有用。

干杯!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM