zend框架2控制器中的基本路径访问

Dil*_*ati 4 zend-framework2

如何在ZF 2中的控制器中调用basePath助手.我必须重定向到我需要基本路径的特定URL.return $ this-> redirect() - > toUrl($ basePath.'/ application/rent/search');

aim*_*eld 7

这是一种简单的方法,可以在控制器中提供所有视图助手.所以你应该能够使用以下内容:

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);
}
Run Code Online (Sandbox Code Playgroud)

  • 请注意,重定向控制器插件还具有toRoute()方法,该方法使基本路径的使用过时. (3认同)