user231791
user231791

Reputation: 301

get URL id in zend framework

I need URL id to get particular data from database in zend framework 2. This is my controller script:

$request = $this->getRequest();

    return new ViewModel(
            array('request' => $request));

and this is view:

echo $this->request;

I got output like:

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

But, I need only property id, that is: 274. What should I do?

Upvotes: 1

Views: 1691

Answers (3)

dev4092
dev4092

Reputation: 2891

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

Upvotes: 0

akond
akond

Reputation: 16035

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

and then in the view

echo $this->property

Upvotes: 1

Fouad Fodail
Fouad Fodail

Reputation: 2643

Just use the getParam() method :

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

In the view :

echo $this->property;

Upvotes: 1

Related Questions