Saqib Omer
Saqib Omer

Reputation: 5477

Zend Framework JSON request url

I am new with ZF1. I am trying to get JSON response for a particular id. I can get all values from table using following code. How can I pass some parameter from url?

public  function emailAction(){

    $emailModel = new test_Model_DbTable_Email();
    $results = $emailModel->getEmails(518); // <-- I want here parameter from url
    $this->_helper->json($results);
    $this->getResponse()->setHttpResponseCode(200);

}

Upvotes: 0

Views: 304

Answers (1)

Mustafa Toker
Mustafa Toker

Reputation: 344

your url should be like :

http://yourdomain.com/index/email/id/14

And u can acces like in action

$this->getRequest()->getParam("id");

you can pass multi paramater :

http://yourdomain.com/index/email/id/14/name/john/surname/doe 

$this->getRequest()->getParam("id");
$this->getRequest()->getParam("name");
$this->getRequest()->getParam("surname");

your code is as follows :

public  function emailAction(){

    $id = $this->getRequest()->getParam("id");

    $emailModel = new test_Model_DbTable_Email();
    $results = $emailModel->getEmails($id); // <-- you want to here parameter from url
    $this->_helper->json($results);
    $this->getResponse()->setHttpResponseCode(200);

}

Upvotes: 1

Related Questions