2

Is there some way to acces the user object from a custom routing class?

I'd like to add a parameter when generating a url, and that parameter is inside the user session, so I need to access it.

The only way I found to access is using the sfContext::getInstance()->getUser(), but it's known to be inefficient.

Thanks!

2 Answers 2

0

I'd write it the way you mention - I've used that method in similar situations and never had an issue performance wise, and suspect you will be the same.

Also, never heard this mentioned as inefficient, but it is a little bit frowned upon because it couples the route to the context. An alternative that would overcome this would be to pass the variable to the route as you would any other parameter (or the user object if you need the whole thing). If you need to do this a lot, you can always make a custom url helper that wraps the existing url_for method, adding this param to any other details passed.

1
0

A workaround I have implemented (for now), is getting some data from somewhere (not ideal, I'm willing to access the user session yet), and set a new parameter inside $params, in the generate method of the custom routing class.

Hope it helps...

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.