将变量从 Javascript 传递到 Zend 框架控制器
Pass variable from Javascript to Zend framework Controller
我有一个如下所示的 Zend 框架控制器。
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\JsonModel;
class myDataController extends AbstractActionController
{
public function indexAction()
{
return array();
}
public function viewHandlerAction()
{
echo $_REQUEST['value'];
$json = new JsonModel(array("abc"=>"1"));
return $json;
}
}
我正在向此 "viewHandlerAction" 方法发出 HTTP post 请求,其中包含一些数据,如下所示。
$http({
method : "POST",
url : "myData/my-data/viewHandler",
data : JSON.stringify(formData)
}).
then(function(response) {
//console.log(response);
}, function(response) {
//console.log(response);
});
我可以发送这个请求并从控制器接收数据而无需任何 problem.But我无法访问我从客户端发送的数据(formData)。
我哪里做错了?
找到答案了。
在 action 方法中,我们可以通过以下方式获取参数列表。
$data = $this->getRequest()->getPost();
我有一个如下所示的 Zend 框架控制器。
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\JsonModel;
class myDataController extends AbstractActionController
{
public function indexAction()
{
return array();
}
public function viewHandlerAction()
{
echo $_REQUEST['value'];
$json = new JsonModel(array("abc"=>"1"));
return $json;
}
}
我正在向此 "viewHandlerAction" 方法发出 HTTP post 请求,其中包含一些数据,如下所示。
$http({
method : "POST",
url : "myData/my-data/viewHandler",
data : JSON.stringify(formData)
}).
then(function(response) {
//console.log(response);
}, function(response) {
//console.log(response);
});
我可以发送这个请求并从控制器接收数据而无需任何 problem.But我无法访问我从客户端发送的数据(formData)。
我哪里做错了?
找到答案了。 在 action 方法中,我们可以通过以下方式获取参数列表。
$data = $this->getRequest()->getPost();