2014-09-26 70 views
-1

首先我是Symfony2的新手。Symfony2無法生成url

當我跑我的項目,它的顯示下一個錯誤:

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'); 
} 

回答

2

您需要使用路徑的名稱,即「frontendinici_contact」來生成它。在您的樹枝模板中,您必須這樣做:

{{ path('frontendinici_contact') }} 

獲取URL。