2

Using Symfony to access url parameters in an action like this

$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 ...

1
  • The easiest thing would probably be to simply use $_GET. (However, you should think about whether your template is the right place to do this in the first place. Sounds like it might rather belong into the controller.) Commented Jan 18, 2016 at 12:09

2 Answers 2

2

You can access the request object from the template directly like this:

$pool = $sf_request->getParameter('pool');
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.