Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZF: How to get current url on any page in the view?

I have a value in general layout. I need to set this value to current url on any page. How to do this?

Thanks to all

like image 819
Anthony Avatar asked Apr 01 '11 08:04

Anthony


2 Answers

In Zend Framework 2 you can use Zend\View\Helper\ServerUrl view helper. It's very simple:

//for example, your current URI is: http://mydomain.com/page/sample/

//get your domain
$uri = $this->serverUrl(); // Output: http://mydomain.com

//get your current URI
$uri = $this->serverUrl(true); // Output: http://mydomain.com/page/sample/

Learn more: http://codingexplained.com/coding/php/zend-framework/create-full-urls-in-zf2-views

like image 90
asologor Avatar answered Nov 16 '22 08:11

asologor


There are few ways you could get the requested url. One is through $_SERVER["REQUEST_URI"], as you did, but off course ZF has its own ways. Two examples are:

  // you can call it in a view or a layout
  $uri = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();

  // or using userAgent view helper in a view or a layout:
  $uri = $this->userAgent()->getServerValue('request_uri');

Hope this helps.

like image 39
Marcin Avatar answered Nov 16 '22 10:11

Marcin