My friends and family are under attack in Ukraine. Donate to protect them directly or help international organizations.

Symfony task “default” context

May 17th, 2011

When creating Symfony 1.4 CLI tasks, I stumbled upon an error message:

The "default" context does not exist.

After searching some old forums, I found a solution. Before you access any Doctrine class, you mus first bootstrap your context correctly. Here is an example:

$config = ProjectConfiguration::getApplicationConfiguration(
  'frontend',
  'dev',
   false
);
sfContext::createInstance($config);
The application name and the environment can come from CLI options. More on Doctrine tasks (I could only find 1.2 equivalent): http://www.symfony-project.org/cookbook/1_2/en/tasks

Previous: What OpenStreetMap is and what it’s not Next: Sync git fork with maintainer