gpt4 book ai didi

php - Symfony 2 - 从另一个 Controller 调用 Controller

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:08:23 25 4
gpt4 key购买 nike

我想在我的 Controller 中使用另一个包中的 Controller 方法。

this->forward方法需要一个Response对象,不知道怎么用。

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

我看到我可以使用服务,但我想知道这是最好的解决方案还是其他解决方案。

最佳答案

$this->forward 按以下顺序接受参数:

  1. 字符串格式的 Controller 操作的逻辑名称,即“AcmeHelloBundle:Hello:fancy”
  2. 以数组格式作为请求变量传递的参数,即 array('名字' => $名字,'颜色'=>'绿色',)

可以使用请求访问函数在 Controller 中访问这些参数。

关于php - Symfony 2 - 从另一个 Controller 调用 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26573490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com