risposta per Zend Framework 2.5.3 utilizzando Doctrine Data-Fixtures.
Non sicuro se questo si applica alle risposte date, ma stanno provando un po 'troppo difficile. Se ispezionate l'oggetto $manager
specificato, troverete che è già lo EntityManager
(di interface ObjectManager
) (almeno in ZF2). Come tale si è in grado di ottenere il Connection
direttamente ed è possibile eseguire senza utilizzare $this->container->get('doctrine.orm.entity_manager')
Di seguito un frammento che uso per creare la prima "sistema" utente, con un FK di riferimento createdBy
a se stessa.
public function load(ObjectManager $manager)
{
$sql = 'INSERT INTO users (
id, username, email, display_name, `password`, created_by)
VALUES (:id, :username, :email, :display_name, :password, :created_by)';
$password = $this->createSuperDuperEncryptedPassword();
// $manager === `EntityManager|ObjectManager`, `->getConnection()` is available
$stmt = $manager->getConnection()->prepare($sql);
$stmt->bindValue(':id', 1);
$stmt->bindValue(':username', 'system');
$stmt->bindValue(':email', '[email protected]');
$stmt->bindValue(':display_name', 'system');
$stmt->bindValue(':password', password);
$stmt->bindValue(':created_by', 1); // Self reference
$stmt->execute();
}
utilizzare Symfony \ Component \ Finder \ Finder; – Nicodemuz