1

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

4

3 回答 3

1

只需使用 getParam() 方法:

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

在视图中:

echo $this->property;
于 2013-09-03T20:10:32.100 回答
1
return array ('property' => $this->params ('property'));

然后在视图中

echo $this->property
于 2013-09-03T21:22:47.997 回答
0

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

于 2014-02-25T10:35:02.117 回答