0

I have a Zend framework Controller as below.

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;
    }
}

I am making a HTTP post request to this "viewHandlerAction" method with some data as below.

$http({
        method : "POST",
        url : "myData/my-data/viewHandler",
        data : JSON.stringify(formData)
    }).
    then(function(response) {
        //console.log(response);

    }, function(response) {
        //console.log(response);
    });

I can send this request and receive the data from the controller without any problem.But I can not access the data(formData) I sent from the client side.

Where have I done wrong?

1 Answer 1

1

Found the answer. In the action method we can get the parameter list with following.

$data = $this->getRequest()->getPost();
Sign up to request clarification or add additional context in comments.

1 Comment

Zend Framework also provides a params() controller plugin to help with this. If you do not want to have to get the request first you can use $this->params()->fromPost(); Documentation is found at framework.zend.com/manual/2.4/en/modules/zend.mvc.plugins.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.