0

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

}

1 Answer 1

1

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

}

Sign up to request clarification or add additional context in comments.

Comments

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.