zend framework 2 base path access in controller

zend-framework2

Solution

Here's an easy method to make all view helpers available from within the controllers. So you should be able to use the following:

public function someAction()
{
    $renderer = $this->serviceLocator->get('Zend\View\Renderer\RendererInterface');
    $url = $renderer->basePath('/application/rent/search');
    $redirect = $this->plugin('redirect');
    return $redirect->toUrl($url);
}

Problem

How can i call basePath helper in controller in ZF 2. I have to redirect to a particular url in which i need base path. return $this->redirect()->toUrl($basePath.'/application/rent/search');

Original source