如何在bootstrap中访问URL参数
我试图在引导文件中捕获 URL 参数,但经过多次尝试后我无法做到这一点。
我已经尝试过,但它不起作用:
protected function _initGetLang() {
$frontController = Zend_Controller_Front::getInstance();
$lang= $frontController->getParam('lang');
}
这是正确的方法吗?
谢谢。
I'm trying to capture a URL parameter in my bootstrap file but after several attempts I'm not able to do it.
I've tried this but it does not work:
protected function _initGetLang() {
$frontController = Zend_Controller_Front::getInstance();
$lang= $frontController->getParam('lang');
}
Is this the right way to do it?
Thks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将无法从引导程序访问请求参数,因为它尚未完成调度/路由过程。我认为使用 控制器插件,根据 URL 执行操作是他们最擅长的。或者,如果您绝对必须在引导程序中执行此操作,则可以使用
getRequestUri()
或$_GET
,或者您可以编写一个快速脚本来自己解析 url。编辑:
在我弄清楚插件如何工作之前,我过去做过一些类似这样的愚蠢的事情:
这至少会给你一个可以
切换
的模块名称在引导程序中。不过,通过正确完成插件,您应该能够做任何您需要的事情。You won't be able to access the request params from the bootstrap because it hasn't yet gone through the dispatch/routing process. I think you'd be better served by using a Controller Plugin, performing actions based on the URL is what they do best. Or if you absolutely have to do it in the bootstrap,
getRequestUri()
or$_GET
is available, or you could write a quick script to parse the url yourself.Edit:
I've done some silly stuff like this in the past before I figured out how plugins work:
This would at least give you a module name that you could
switch
on in the bootstrap. You should be able to do anything you need with the plugins done correctly though.