I have created a custom task in symfony (1.3.6), running on Ubuntu 10.0.4.
I am generating urls in the task. This is a snippet of some of my code:
// In the custom task (lib/task/mySomethingSomethingTask.php)
protected function execute($arguments = array(), $options = array())
{
//create a context
$app = sfProjectConfiguration::getApplicationConfiguration('frontend', 'prod', true);
sfContext::createInstance($app);
sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url', 'Asset', 'Tag'));
$routing = $this->getProductionRouting();
// initialize the database connection
$databaseManager = new sfDatabaseManager($this->configuration);
$connection = $databaseManager->getDatabase($options['connection'])->getConnection();
// add your code here
// ...
}
/**
* Gets routing with the host url set to the url of the production server
* @return sfPatternRouting
*/
protected function getProductionRouting()
{
$routing = $this->getRouting();
$routingOptions = $routing->getOptions();
$routingOptions['context']['host'] = sfConfig::get('app_server_name', 'www.example.com');
$routing->initialize($this->dispatcher, $routing->getCache(), $routingOptions);
return $routing;
}
// My frontend/config/routing.yml
foobar_by_name:
url: /foo/bar/:name/someguy.html
param: { module: something, action: somethingDarkSide }
// In the model layer (the method called by the task)
public static function getSomeData(sfRouting $routing)
{
$name = 'family-guy'
$parameters = array('name'=>$name);
$url = $routing->generate('foobar_by_name', $parameters, true); // <- ERROR !
}
When the method getSomeData() is called in the task, I get the error message:
The route "foobar_by_name" does not exist.
Does anyone know how to resolve this?