我需要URL id来从zend框架2中的数据库中获取特定数据。 这是我的控制器脚本:
$request = $this->getRequest();
return new ViewModel(
array('request' => $request));
这是观点:
echo $this->request;
我的输出如下:
GET http://public.localhost.com:80/property/274 HTTP/1.1 Cookie: _ga=GA1.2.1235676771.1376588476; PHPSESSID=7bs59pfipit9eekd3tqmcocna3 Host: public.teamleads.com Connection: keep-alive Cache-Control: max-age=0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8
但是,我只需要属性id,即:274。 我该怎么办?
答案 0 :(得分:1)
只需使用getParam()方法:
// $request = $this->getRequest();
return new ViewModel(
array('property' => $this->getEvent()->getRouteMatch()->getParam('property'))
);
在视图中:
echo $this->property;
答案 1 :(得分:1)
return array ('property' => $this->params ('property'));
然后在视图中
echo $this->property
答案 2 :(得分:0)
$ requested = $ this-> getRequest(); $ ad_id = $ requested-> getParam('ad_id'); //获取advertiser_id $ c_id = $ requested-> getParam('c_id');