在我的CakePHP 3应用程序,一个控制器重定向后,我得到这个错误:CakePHP的3重定向器
Error: [LogicException] Controller action can only return an instance of Response
Request URL: /mycontroller/
Stack Trace:
#0 /var/www/vhosts/example.com/httpdocs/vendor/cakephp/cakephp/src/Routing/Dispatcher.php(87): Cake\Routing\Dispatcher->_invoke(Object(App\Controller\SigninsController))
#1 /var/www/vhosts/example.com/httpdocs/webroot/index.php(37): Cake\Routing\Dispatcher->dispatch(Object(Cake\Network\Request), Object(Cake\Network\Response))
#2 {main}
关于把CakePHP 2 controller documentation重定向是这样的:
$this->redirect('/orders/thanks');
$this->redirect('http://www.example.com');
return $this->redirect(
array('controller' => 'orders', 'action' => 'confirm')
);
但在CakePHP中3 documentation似乎是这样的:
return $this->redirect('/orders/thanks');
return $this->redirect('http://www.example.com');
return $this->redirect(
['controller' => 'Orders', 'action' => 'thanks']
);
当我添加在$this->redirect
之前3210字,错误得到解决。这是否会造成问题?因为我看不到cakephp 3 migration guide中的返回重定向部分。迁移指南只提到第三个参数被删除。
引用[迁移指南](http://book.cakephp.org/3.0/en/appendices/3-0-migration-guide.html#id2):“该方法不能再发送响应并退出脚本,而是返回一个带有适当头文件的Response实例。“ – ADmad