Précédent   Forum des professionnels en informatique > PHP > Bibliothèques et frameworks > symfony
symfony Forum d'entraide sur le framework PHP symfony. Avant de poster : cours symfony et FAQ symfony
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 12/09/2011, 12h32   #1
Candidat au titre de Membre du Club
 
Homme Stéphane Bouvry
Intégrateur Web
Inscription : mars 2002
Messages : 8
Détails du profil
Informations personnelles :
Nom : Homme Stéphane Bouvry
Localisation : France

Informations professionnelles :
Activité : Intégrateur Web

Informations forums :
Inscription : mars 2002
Messages : 8
Points : 13
Points : 13
Par défaut Exécuter une action dans une tâche

Bonjour,

Le titre est explicite, j'ai simplement besoin d'exécuter une action d'un module depuis une tâche symfony. (J'ai trouvé la solution dans l'autre sens)

PS : L'action d'origine affiche un message texte basique sans Layout (Mais elle utilise les des partials dans le module en question ou envoyer un mail).

Cordialement
jacksay est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/09/2011, 12h34   #2
Candidat au titre de Membre du Club
 
Homme Stéphane Bouvry
Intégrateur Web
Inscription : mars 2002
Messages : 8
Détails du profil
Informations personnelles :
Nom : Homme Stéphane Bouvry
Localisation : France

Informations professionnelles :
Activité : Intégrateur Web

Informations forums :
Inscription : mars 2002
Messages : 8
Points : 13
Points : 13
Bonjour moi-même

J'ai trouvé une bidouille (ça fonctionne... savoir si c'est élégant...).

Je me suis fait un petit pense bête sur mon blog car ce n'est pas le genre de manipulation qu'on fait souvent : Executer une action dans une tâche symfony

Voici le code de la tâche pour la postérité et recevoir votre avis (et idée d'amélioration) :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
  protected function execute($arguments = array(), $options = array())
  {
    // On récupère la configuration
    $conf = sfApplicationConfiguration::getApplicationConfiguration('frontend', 'prod', true);
 
    // On récupère le contexte
    $context = sfContext::createInstance($conf);
 
    // On récupère l'action à executer
    $action = $context->getController()->getAction('exemple', 'monAction');
 
    // On execute l'action
    $action->execute(null);
 
    // et enfin on récupère le rendu de l'action via la sfResponse
    $this->logSection('exec', $action->getResponse()->getContent());
  }
La partie qui me tulupine c'est que je n'ai pas trouvé un moyen de récupérer l'app et l'environnement de la commande pour les exploiter dans la ligne qui récupérer la configuration du context :

Code :
1
2
3
 
// LA
$conf = sfApplicationConfiguration::getApplicationConfiguration('frontend', 'prod', true);
Ces infos étant pourtant disponibles dans la méthode configure de la tâche générée :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
protected function configure()
  {
    // // add your own arguments here
    // $this->addArguments(array(
    //   new sfCommandArgument('my_arg', sfCommandArgument::REQUIRED, 'My argument'),
    // ));
 
    $this->addOptions(array(
      new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'frontend'),
      new sfCommandOption('prod', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
      new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'),
      // add your own options here
    ));
 
    $this->namespace        = '';
    $this->name             = 'testCron';
    $this->briefDescription = '';
    $this->detailedDescription = <<<EOF
The [testCron|INFO] task does things.
Call it with:
 
  [php symfony testCron|INFO]
EOF;
  }
jacksay est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 23h54.


 
 
 
 
Partenaires

Hébergement Web