RSS Feed

symfony 1.2+ tasks: The “default” context does not exist

If you happen to run into the error ‘The “default” context does not exist’ when running a custom symfony task the chances are you’re using a method of an object which utilizes sfContext. It seems symfony does not create an instance of sfContext by default and thus the error is returned. The only solution to this issue that I have found so far is to create a new instance of sfContext with your tasks configuration as the set parameters. The following should be added to the top of the tasks execute method:



protected function execute ($arguments = array(), $options = array())
  // ... Your code

You should no longer run into the context error within tasks.

Posted in PHP on the 8th February 2010

4 people have spoken their minds!

  1. Dan says:

    Have you had any luck doing this with 1.3/1.4?

    In 1.4 if I try this, I get:

    PHP Catchable fatal error: Argument 1 passed to sfContext::createInstance() must be an instance of sfApplicationConfiguration, instance of ProjectConfiguration given

  2. srcnix says:


    You need to pass your project configuration to the createInstance() method.

    You can do this by passing $this->configuration (If set) otherwise you can get your project configuration from the sfProjectConfiguration class:


    The getApplicationConfiguration() method accepts three parameters; Application, environment and whether to turn debugging on.

    sfProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);

    The best way around this would not be using an sfContext instance within library files however sometimes this is not possible.

    Feel free to post the code here and I will help you debug it if my comment hasn’t helped.

  3. someone says:

    fixed my problem. thanks!


Your email address will not be published. Required fields are marked *