Zend 框架 JSON 请求 url
Zend Framework JSON request url
我是 ZF1 新手。我正在尝试获取特定 ID 的 JSON 响应。我可以使用以下代码从 table 获取所有值。如何从 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);
}
你的 url 应该是这样的:
http://yourdomain.com/index/email/id/14
而且你可以像实际操作一样访问
$this->getRequest()->getParam("id");
你可以传递多参数:
http://yourdomain.com/index/email/id/14/name/john/surname/doe
$this->getRequest()->getParam("id");
$this->getRequest()->getParam("name");
$this->getRequest()->getParam("surname");
您的代码如下:
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);
}
我是 ZF1 新手。我正在尝试获取特定 ID 的 JSON 响应。我可以使用以下代码从 table 获取所有值。如何从 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);
}
你的 url 应该是这样的:
http://yourdomain.com/index/email/id/14
而且你可以像实际操作一样访问
$this->getRequest()->getParam("id");
你可以传递多参数:
http://yourdomain.com/index/email/id/14/name/john/surname/doe
$this->getRequest()->getParam("id");
$this->getRequest()->getParam("name");
$this->getRequest()->getParam("surname");
您的代码如下:
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);
}