如何在cakephp 3.0中使用requestAction [英] How to use requestAction in cakephp 3.0

查看:70
本文介绍了如何在cakephp 3.0中使用requestAction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在2.0版本中,我使用 requestAction 这样:

At 2.0, I use requestAction like this:

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

但是在3.0版本中,我没有使用 requestAction 显示任何内容。我不知道如何编写选项数据源。

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

推荐答案

在Cake 3中,requestAction的结果必须通过响应对象返回,而不是像在其中那样直接返回Cake2。使用JSON编码最容易实现。

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.

在您通过requestAction调用的函数中:

In the function that you are calling through requestAction:

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

然后在视图中,options参数将为

And then in the view your options parameter would be

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

这篇关于如何在cakephp 3.0中使用requestAction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆