在zend框架中获取URL id


get URL id in zend framework

我需要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。我该怎么办?

只需使用getParam()方法:

// $request = $this->getRequest();
return new ViewModel(  
           array('property' => $this->getEvent()->getRouteMatch()->getParam('property'))
       );

视图中:

echo $this->property;
return array ('property' => $this->params ('property'));

然后在视图中

echo $this->property

$requested=$this->getRequest();$ad_id=$requested->getParam('ad_id')//获取advertiser_id$c_id=$requested->getParam('c_id');