如何从symfony2中的php模板调用控制器操作

如何从symfony2中的php模板调用控制器操作,symfony,Symfony,早上好 由于我是新来symfony的,您对我帮助很大,我衷心感谢您 在我的suces.html.php中 我得到session变量 $var=$app->getSession()->get('id'); //Now iam checking whether the variable is set or not if(!isset($var)) { //here i need to call to a controller for a particular action }

早上好 由于我是新来symfony的,您对我帮助很大,我衷心感谢您

在我的suces.html.php中 我得到session变量

$var=$app->getSession()->get('id');

//Now iam checking whether the variable is set or not 
if(!isset($var))
{
  //here i need to call to a controller for a particular action
}
我使用了e
cho$view['actions']->render('RepairLoginBundle:Login:Login')


它向我显示找不到登录路径:Login

您可能正在查找渲染操作

在你看来,你可以做到

<div id="sidebar">
    <?php echo $view['actions']->render(
        new \Symfony\Component\HttpKernel\Controller\ControllerReference('RepairLoginBundle:Login:login', array())
    ) ?>
</div>

上述代码从视图调用
RepairLoginBundle:Login:Login
controller


文档:(参见PHP选项卡)

我认为从视图调用控制器操作对于MVC来说是不正确的。您是否需要使用视图帮助器?我以这种方式使用了您所说的代码,但它抛出了错误类“Controller Reference”,而不是found我修改了代码并以这种方式使用,但它抛出了错误类“Controller Reference”,而不是foundtry add use Symfony\Component\HttpKernel\Controller\ControllerReference;使用use语句或您可以这样做谢谢您我的问题已被清除,但有一个小问题已被删除,即我使用了if(!isset($var))从那里调用控制器查看。如果设置了该变量,它将显示下面的html页面。问题是,即使未设置变量,它也会显示两个视图,如果您能解决我的问题,请告诉我,我将详细解释您