[英]How to access a url parameter in template using Symfony (not within the action)?
Using Symfony to access url parameters in an action like this 在这样的操作中使用Symfony访问url参数
$this->getRequestParameter('myUrlParameter');
How can I access this parameter in the root template, where I am not within the action? 如何在根模板中访问该参数,而该根模板不在操作中? I tried many things already like
我已经尝试了很多东西
echo $context->getRequest()->getParameter('pool');
and 和
echo $context->getParameter('pool');
Which didn't work. 哪个没有用。 With
同
echo sfContext::getInstance()->getRouting()->getCurrentInternalUri();
I get the whole url - which is not what I want. 我得到了整个网址-这不是我想要的。 I feel like there must be a simple way to access this information ...
我觉得必须有一种简单的方法来访问此信息...
您可以像这样直接从模板访问请求对象:
$pool = $sf_request->getParameter('pool');
You need to pass it to the view via controller: 您需要通过控制器将其传递给视图:
public function yourController(sfWebRequest $request)
{
$this->myUrlParameter = $this->getRequestParameter('myUrlParameter');
}
Trying to access it directly, you are fighting with the framework, not using it. 尝试直接访问它,您正在使用该框架,而不是在使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.