This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

Day 6 - sfContext vs getContext()

Discussion around this tutorial for symfony 1.0.x

Day 6 - sfContext vs getContext()

by leonard » Thu Feb 02, 2006 1:01 pm


I'm now at day 6 of the askeet tutorial. At the refactoring bit, the tutorial is changing $this->getContext()->getUser() in myLoginValidator class with sfContext::getInstance()->getUser().

What are the difference between these two? I tried to still use $this->getContext()->getUser()->signIn() but it wouldn't work. How do I know when to use sfContext or getContext()?
Junior Member
Posts: 4
Joined: Sat Oct 29, 2005 4:30 pm

Re: Day 6 - sfContext vs getContext()

by weaverryan » Sun Jun 21, 2009 9:53 pm

Hey Leonard-

sfContext::getInstance() is always the correct method to return the current context. In some cases (none come to mind, but it still may be possible), the class you're working inside may have a getContext() method as well. If that's the case, all that getContext() method will do is call sfContext::getInstance().

you can never go wrong with sfContext::getInstance()

Ryan Weaver - CEO of KnpLabs US
Offering Symfony2 training May 19th & 20th - Nasvhille, TN and June 6th & 7th - New York, NY
User avatar
Faithful Member
Posts: 784
Joined: Sat Nov 10, 2007 1:50 am
Location: Nashville, TN