我需要从另一个控制器内的不同控制器访问方法。我该怎么做?我可以用吗this->get
method?
我可以将控制器包含在当前控制器中并创建它的对象并通过该对象访问该方法吗?这样做“可以”吗?
我想调用另一个控制器的表单方法---newAction。
如果您不想将类定义为服务,因为对我来说这不是一个好的做法,@Qoop 引用法比安也这么说 https://github.com/symfony/symfony-docs/issues/457,您可以使用转发:
http://symfony.com/doc/current/controller/forwarding.html http://symfony.com/doc/current/controller/forwarding.html
public function indexAction($name)
{
$response = $this->forward('AcmeHelloBundle:Hello:fancy', array(
'name' => $name,
'color' => 'green',
));
// ... further modify the response or return it directly
return $response;
}
如果您需要将内部控制器操作的输出嵌入到模板中,则Symfony 文档 http://symfony.com/doc/current/templating/embedding_controllers.html也有一些东西。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)