baseUrl view helper not working on ZendFramework 2

2019-07-17 06:29发布

问题:

I'm testing with the new Zend Framework 2, and I found a problem when trying to use the baseUrl view helper, I'm getting the following error when calling $this->baseUrl() inside my phtml view file;

Debug Error:

C:\Zend\ZendServer\share\ZendFramework2\library\Zend\ServiceManager\ServiceManager.php line 424 - Uncaught exception 'Zend\ServiceManager\Exception\ServiceNotFoundException' with message 'Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for baseUrl' in C:\Zend\ZendServer\share\ZendFramework2\library\Zend\ServiceManager\ServiceManager.php:424

回答1:

This looks like ZF1 feature, ZF2 has helper Zend\View\Helper\BasePath

in the view $this->basePath();