How to get base path with domain name in Zend Framework 2 layout

As you maybe know, if you want to get the base path in Zend Framework 2 layout you can use this variable: $basePath or function $this->basePath(). But sometimes these variables doesn't work correctly.

So, in this tutorial I want to show you an another way to get base path with domain name in Zend Framework 2 layout.

To get base path with domain name you must only add this code:

$base = $this->url('home',array(),array('force_canonical' => true));

and

<a href="<?php echo $base;  ?>">Home</a>

Result:

http://domain.com/

zend









Leave a Comment