Zend Framework 2 控制器中的基本路径访问 [英] zend framework 2 base path access in controller
本文介绍了Zend Framework 2 控制器中的基本路径访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何在 ZF 2 中的控制器中调用 basePath 助手.我必须重定向到我需要基本路径的特定 url.return $this->redirect()->toUrl($basePath.'/application/rent/search');
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');
推荐答案
这里有一个简单方法来制作所有视图助手可从控制器内获得.因此,您应该能够使用以下内容:
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);
}
这篇关于Zend Framework 2 控制器中的基本路径访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文