简体   繁体   English

symfony - 如何进行路由

[英]symfony - how to do routing

I need help with symfony, how to do the routing and add the page to the finished project, this is where I added the new routing: src / BlogBundle / Resources / config / routing_news.yml here is the code:我需要 symfony 的帮助,如何进行路由并将页面添加到完成的项目中,这是我添加新路由的地方:src/BlogBu​​ndle/Resources/config/routing_news.yml 这里是代码:

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

Then I added to the controller: src / BlogBundle / Controller / PageController.php code:然后我在控制器中添加: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()
    ]);
}

Well, I created the file: reset.html.twig in src / BlogBundle / Resources / views / Page.好吧,我在 src/BlogBu​​ndle/Resources/views/Page 中创建了文件:reset.html.twig。 So this is what I did wrong, because when I go to this / page / reset_mail, nothing happens.所以这就是我做错的地方,因为当我去这个/页面/reset_mail 时,什么也没有发生。 What I did wrong, and how to do it right?我做错了什么,如何做对?

You should use annotations for your routing.您应该为路由使用注释。

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

It's good practice ( https://symfony.com/doc/current/best_practices.html#don-t-use-annotations-to-configure-the-controller-template ).这是一个很好的做法( https://symfony.com/doc/current/best_practices.html#don-t-use-annotations-to-configure-the-controller-template )。

It's really simple to use annotation and better.使用注释真的很简单,而且更好。

Hope that's will be useful.希望这会很有用。

Cheers !干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM