我在Symfony中有一个小项目。现在尝试链接我的树枝模板(tours.html.twig)。我在浏览器中有一个加载区域设置的页面(键入:bikelando.localhost)。在此页面上,我具有指向其他页面tour.html.twig的链接。我正在尝试做的是使地址bikelando.localhost / tours显示游览模板。我想我尝试了互联网上的所有内容,但没有任何效果。这是... / bikelando / templates / index.html.twig中的代码,其中包含指向旅行团的链接
<a ... href="{{ path('tours') }}">Tours</a>
这是我的... / bikelando / config / routes.yaml代码(适用于index.html.twig,但不适用于旅行)
index:
path: /
controller: Symfony\Bundle\FrameworkBundle\Controller\TemplateController::templateAction
defaults:
template: 'index.html.twig'
tours:
path: /tours
controller: App\Controller\ToursController::show
这是我的... / bikelando / src / Controller / ToursController.php
class ToursController extends AbstractController
{
/**
* @Route("/tours", name="tours")
*/
public function show()
{
return $this->render('tours.html.twig');
}
}
当我键入bikelando.localhost / tours时,所有这些都会使我收到404错误,应用未加载此模板,但是bikelando.localhost正在加载确定。我感到非常困惑和沮丧,有人可以指出我的错误吗?
您可以在Yaml和您的控制器中进行选择,也许选择一个。如果您想使其非常简单,请在控制器中而不是在Yaml中执行。在控制器中,您在类实例化上方是否还有其他路线?您的模板是否正确? (不在其他存储库中)