Je cours Symfony 1.3.6 sur Ubuntu 10.0.4 LTS.Utilisation des routes pour générer des URL dans une tâche Symfony
J'ai écrit une tâche Symfony qui génère un rapport contenant des liens (URL).
Voici un extrait de la méthode execute()
dans ma classe de tâche:
protected function execute($arguments = array(), $options = array())
{
//create a context
sfContext::createInstance($this->configuration);
sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url', 'Asset', 'Tag'));
...
$url = url_for("@foobar?cow=marymoo&id=42");
// Line 1
echo '<a href="'.$url.'">This is a test</a>';
// Line 2
echo link_to('This is a test', $url);
}
Le nom de l'itinéraire est défini comme suit:
foobar:
url: /some/fancy/path/:cow/:id/hello.html
param: { module: mymodule, action: myaction }
Lorsque cela est exécuté, le lien généré est:
Ligne 1 produit cette sortie:
./symfony/symfony/some/fancy/path/marymoo/42/hello.html
au lieu de l'attendre:
/some/fancy/path/marymoo/42/hello.html
Ligne 2 génère une erreur:
Unable to find a matching route to generate url for params "array ( 'action' => 'symfony', 'module' => '.',)".
Encore une fois, l'URL attendue est:
/some/fancy/path/marymoo/42/hello.html
Comment puis-je résoudre ce?
+1 pour l'extrait sympa et succinct qui me montre comment résoudre ce problème. Je vais légèrement modifier le code pour convenir à ce que je fais, le tester, si ça marche, j'accepterai cette réponse. – morpheous
Ça marche! Merci à vous, merci, merci! :) – morpheous
Où devrais-je mettre cet extrait?Je ne peux pas appeler $ this-> getRouting() à partir d'une tâche:/ – JavierIEH