如何链接到 Twig 模板中的另一个页面?

问题描述 投票:0回答:1

我的控制器中的这段代码加载我的第一页:

/**
 * @Route("/main")
 */
public function indexAction()
{
    $templating = $this->container->get('templating');
    $html = $templating->render('base.html.twig');    
    return new Response($html);
}

我的

base.html.twig
中有一个链接:

<a href="{{ path('options') }}">My options</a> 

按下链接后,我想使用我的

@Route("/options")
并转到我的选项页面。

如何正确做?

php symfony
1个回答
5
投票

试试这个:

 /**
 * @Route("/options", name="route-name")
 */
public function showAction() {

    return new Response("This will be options page:");
}

现在使用路线名称:

  <a href="{{ path('route-name') }}">My options</a> 
© www.soinside.com 2019 - 2024. All rights reserved.