【问题标题】:get URL id in zend framework在zend框架中获取URL id
【发布时间】:2013-09-03 19:23:32
【问题描述】:

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

【问题讨论】:

    标签: php zend-framework zend-framework2


    【解决方案1】:

    只需使用 getParam() 方法:

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

    在视图中:

    echo $this->property;
    

    【讨论】:

      【解决方案2】:
      return array ('property' => $this->params ('property'));
      

      然后在视图中

      echo $this->property
      

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多