0
我有一個Zend框架控制器如下。從Javascript傳遞變量到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發佈請求,其中的一些數據如下。
$http({
method : "POST",
url : "myData/my-data/viewHandler",
data : JSON.stringify(formData)
}).
then(function(response) {
//console.log(response);
}, function(response) {
//console.log(response);
});
我可以發送此請求並從控制器接收數據沒有任何問題。但我無法訪問從客戶端發送的數據(formData)。
我在哪裏做錯了?
Zend Framework還提供了一個'params()'控制器插件來幫助解決這個問題。如果你不想先得到請求,你可以使用'$ this-> params() - > fromPost();'文檔可以在https://framework.zend.com/manual/2.4/en/找到。模塊/ zend.mvc.plugins.html –