comment bien commencer avec doctrine2 ?
Bonjour, j'ai réussi a installer proprement doctrine 2 avec Zend 1.11,
comme il y avais plusieurs tuto, j'ai réussi a en fini un.
j'ai donc modifier mon boostrap, je par sur un dossier vierge qui a été crée par zf tool avec le create project
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
/**
* generate registry
* @return Zend_Registry
*/
protected function _initRegistry(){
$registry = Zend_Registry::getInstance();
return $registry;
}
/**
* Register namespace Default_
* @return Zend_Application_Module_Autoloader
*/
protected function _initAutoload()
{
$autoloader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'Default_',
'basePath' => dirname(__FILE__),
));
return $autoloader;
}
/**
* Initialize Doctrine
* @return Doctrine_Manager
*/
public function _initDoctrine() {
// include and register Doctrine's class loader
require_once('Doctrine/Common/ClassLoader.php');
$classLoader = new \Doctrine\Common\ClassLoader(
'Doctrine',
APPLICATION_PATH . '/../library/'
);
$classLoader->register();
// create the Doctrine configuration
$config = new \Doctrine\ORM\Configuration();
// setting the cache ( to ArrayCache. Take a look at
// the Doctrine manual for different options ! )
$cache = new \Doctrine\Common\Cache\ArrayCache;
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
// choosing the driver for our database schema
// we'll use annotations
$driver = $config->newDefaultAnnotationDriver(
APPLICATION_PATH . '/models'
);
$config->setMetadataDriverImpl($driver);
// set the proxy dir and set some options
$config->setProxyDir(APPLICATION_PATH . '/models/Proxies');
$config->setAutoGenerateProxyClasses(true);
$config->setProxyNamespace('App\Proxies');
// now create the entity manager and use the connection
// settings we defined in our application.ini
$connectionSettings = $this->getOption('doctrine');
$conn = array(
'driver' => $connectionSettings['conn']['driv'],
'user' => $connectionSettings['conn']['user'],
'password' => $connectionSettings['conn']['pass'],
'dbname' => $connectionSettings['conn']['dbname'],
'host' => $connectionSettings['conn']['host']
);
$entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
// push the entity manager into our registry for later use
$registry = Zend_Registry::getInstance();
$registry->entitymanager = $entityManager;
return $entityManager;
}
} |
j'ai crée un fichier Test.php à la racine du modèle
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
<?php
/**
* @Entity
* @Table(name="test123")
*/
class Default_Model_Test
{
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/** @Column(type="string") */
private $name;
public function setName($string) {
$this->name = $string;
return true;
}
} |
après avoir taper la commande
Code:
1 2
|
./doctrine orm:schema-tool:create |
j'ai bien une table qui s'appele "test123", donc je suppose que mon installer c'est bien dérouler.
Comme tous les tutos sont différent, je suis un peu perdu, j'aimerais effacer cette table de test et refaire la même chose mais avec un fichier YML.
comment comment je peux m'y prendre ? et travailler dans quels dossiers ?
pour bien faire les choses faut t'il appeller la commande "zf create db-table classetable table" ? ensuite on crée un fichier YML
ou bien le zf tool est capable de crée tous seul un yaml ?
dans mon dossier library, j'ai un sous dossier qui s'appelle "Doctrine" et qui se composent de 4 sous répértoire "dball","orm","Symfony".
je vous remercie d'avance de vos conseils :)