I would like to get Base URL in controller of Zend Framework 2 to pass as value of src attributes of img tag.I put my image in public folder.
How can I get Base URL in controller of Zend Framework 2 ??
I would like to get Base URL in controller of Zend Framework 2 to pass as value of src attributes of img tag.I put my image in public folder.
How can I get Base URL in controller of Zend Framework 2 ??
You can use ServerUrl view helper for absolute URL's and BasePath for the relative ones in any view.
Edit: Oh sorry, question was about getting that value in controller level, not view. In any controller you can do this:
Update for Zend Framework 3
Since controllers are not ServiceLocatorAware by default in ZF3, you need to inject the helper instance to your controller, preferably using a factory.
For rookies, an example factory may look like:
and a constructor signature on controller something like:
You can also use BasePath Helper in your view.
And if it is for setting the
src
attribute of an image, no need to set it at controller level.