首先,我是Symfony2的新手。
当我运行我的项目时,它会显示下一个错误:
An exception has been thrown during the rendering of a template ("Unable to
generate a URL for the named route "/contact/" as such route does not exist.")
in frontendiniciBundle:Default:index.html.twig at line 4.
/frontend/iniciBundle/Resources/config/routing.yml中的路线
frontendinici_homepage:
path: /index/
defaults: { _controller: frontendiniciBundle:Principal:index }
frontendinici_contact:
path: /contacto/
defaults: { _controller: frontendiniciBundle:Principal:contact }
控制器的代码
class PrincipalController extends Controller
{
public function indexAction()
{
return $this->render('frontendiniciBundle:Default:index.html.twig', array('contactourl' => '/contacto/'));
}
public function contactAction(){
return $this->render('frontendiniciBundle:Default:contact.html.twig');
}
答案 0 :(得分:2)
您需要使用路线的名称,即" frontendinici_contact"生成它。在Twig模板中,您必须执行此操作:
{{ path('frontendinici_contact') }}
获取网址。