How to use requestAction in cakephp 3.0

人走茶凉 提交于 2019-12-14 04:08:54

问题


At 2.0, I use requestAction like this:

<?=$this->Form->input('list',array('options'=>$this->requestAction(……)?>

But At 3.0, I use requestAction nothing display. I don't know how to write options data source.


回答1:


In Cake 3, the results from requestAction must be returned through the response object rather than directly like they were in Cake 2. This is most easily accomplished with JSON encoding.

In the function that you are calling through requestAction:

$options = $table->find(...);
$this->response->body(json_encode($options));
return $this->response;

And then in the view your options parameter would be

'options'=>json_decode($this->requestAction(……), true)


来源:https://stackoverflow.com/questions/30591852/how-to-use-requestaction-in-cakephp-3-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!