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
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With