2013-10-05 34 views
0

这是我的路线Symfony的2 - 不能得到变量

homepage: 
    pattern: /{name}.{ext} 
    defaults: 
     _controller: DprocMainBundle:Index:index 
     name: index 
     ext: php 
    requirements: 
     ext: php 
     name: index 

,我想在我的树枝模板来显示(名称)。所以控制器得到变量,并通过数组将其发送

class IndexController extends Controller 
{ 
    public function indexAction($index) 
    { 
     return $this->render('DprocMainBundle:Dproc:index.html.twig', array('index' => $index)); 
    } 
} 

意见

<title>{% block title %}Welcome - {{ name }}{% endblock %}</title> 

有错误:

Controller "Dproc\MainBundle\Controller\IndexController::indexAction()" requires that you provide a value for the "$index" argument (because there is no default value or because there is a non optional argument after this one).

+2

将'$ index'更改为'$ name' – tttony

回答

1

在你的控制器应该是这样的:

class IndexController extends Controller 
{ 
    public function indexAction($name) 
    { 
     return $this->render('DprocMainBundle:Dproc:index.html.twig', array('name' => $name)); 
    } 
} 

你应该c将变量的名称 - $index更改为$name,因为您在路由中声明了它。而且,你也在枝条中使用它。

+0

是的,我已经做到了。 –