【发布时间】:2018-03-20 10:09:55
【问题描述】:
CakePHP 3.5.13
如果需要将当前action转发到同一个控制器上的不同action,可以使用
Controller::setAction()更新请求对象,修改将要渲染的视图模板,转发执行到命名的action:
// From a delete action, you can render the updated
// list page.
$this->setAction('index');
但这似乎不起作用。
例如,在我的控制器中,我有 2 个函数,index() 和 apply_filters()。我想在执行apply_filters() 后将用户重定向回index()。
所以我这样做了:
public function apply_filters()
{
$this->autoRender = false;
// code for applying filters
$this->setAction('index');
}
public function index()
{
debug('index');
}
apply_filters()没有视图,所以$this->autoRender = false;
当用户在 URL /apply-filters 上时,它只是停留在那里而不重定向回 index()。
如果我将$this->setAction('index') 替换为return $this->redirect(['controller' => 'Front', 'action' => 'index']);
,它绝对可以正常工作
有什么想法吗?
【问题讨论】:
标签: cakephp cakephp-3.0