la réponse est donc la suivante :
$databaseManager = new sfDatabaseManager($this->configuration);
$conn = $databaseManager->getDatabase('master')->getConnection();
Mais mon object $conn n'est pas de type Doctrine_Connection mais PDO.
Lors de mon $object->save($conn); j'ai donc une fatal error...
PHP Catchable fatal error: Argument 1 passed to Product::save() must
be an instance of Doctrine_Connection, inst
ance of PDO given, called in D:\Projets\test\lib\task
\importProductTask.class.php on line 185 and defined in D:\Projets\
test\lib\model\doctrine\Product.class.php on line 45
On 27 oct, 13:47, smellycat37 <[email protected]> wrote:
> Merci
>
> On 26 oct, 23:57, Alexandre SALOME <[email protected]> wrote:
>
> > Bonjour,
>
> > Tu peux utiliser le script :
>
> > ./symfony generate:task --with-database="doctrine"
>
> > Ca te génère du code dans /lib/task
>
> > La réponse se trouve là.
>
> > Le 26 octobre 2009 17:48, smellycat37 <[email protected]> a écrit :
>
> > > bonjour,
>
> > > Je voudrais exécuter une tâche mais je n'arrive pas à récupérer la
> > > connexion de mon objet user (master)...
>
> > > ---------------------------------------------------------------------------------------------------------------
> > > database.yml
>
> > > ------------------------------------------------------------------------------------
> > > all:
> > > master:
> > > class: sfDoctrineDatabase
> > > param:
> > > dsn: 'pgsql:host=localhost;dbname=master'
> > > username: 'root'
> > > password: 'pass'
> > > encoding: utf8
> > > slave:
> > > class: sfDoctrineDatabase
> > > param:
> > > dsn: 'pgsql:host=serv1.dev.fr;dbname=slave'
> > > username: postgres
> > > password: postgres
> > > encoding: utf8
>
> > > ---------------------------------------------------------------------------------------------------------------
> > > schema.yml
>
> > > ------------------------------------------------------------------------------------
> > > connection: master
>
> > > User:
> > > columns:
> > > id: {type: integer(20), primary: true, autoincrement: true,
> > > sequence: customer_id}
>
> > > ---------------------------------------------------------------------------------------------------------------
> > > importuserTask.class.php
>
> > > ------------------------------------------------------------------------------------
> > > ...
> > > protected function execute($arguments = array(), $options = array())
> > > {
> > > // 1-
> > > $obj = new User();
> > > $conn = $obj->getTable()->getConnection();
> > > // 2-
> > > $databaseManager = new sfDatabaseManager($this->configuration);
> > > $conn = $databaseManager->getDatabase('master')->getConnection();
> > > // 3-
> > > $manager = Doctrine_Manager::getInstance();
> > > $conn = $manager->getConnectionForComponent('Doctrine_Record');
> > > ...
> > > }
> > > ...
>
> > > Quelqu'un serait comment faire?
>
> > --
> > Alexandre Salomé -- [email protected]
--~--~---------~--~----~------------~-------~--~----~
Vous avez reçu ce message, car vous êtes abonné au groupe Groupe "Symfony-fr"
de Google Groupes.
Pour transmettre des messages à ce groupe, envoyez un e-mail à
l'adresse [email protected]
Pour résilier votre abonnement à ce groupe, envoyez un e-mail à
l'adresse [email protected]
Pour afficher d'autres options, visitez ce groupe à l'adresse
http://groups.google.com/group/symfony-fr?hl=fr
-~----------~----~----~----~------~----~------~--~---