Ver Mensaje Individual
  #27 (permalink)  
Antiguo 27/03/2012, 07:25
Avatar de masterpuppet
masterpuppet
Software Craftsman
 
Fecha de Ingreso: enero-2008
Ubicación: Montevideo, Uruguay
Mensajes: 3.550
Antigüedad: 16 años, 3 meses
Puntos: 845
Respuesta: Empezando con Doctrine 2.2.1

Vamos por partes, el find deberia ser algo asi:

Código PHP:
Ver original
  1. $em->find('Entity\Category', 1);

Ahora con respecto a como lo estas utilizando, parece ActiveRecord, no es la idea en D2 y si bien son pruebas ten en cuenta que el DQL debería ir en los repositorios.

Te dejo un ejemplo de como podría ser, algo así:

DoctrineLanzador.php
Código PHP:
Ver original
  1. ...
  2. $em = EntityManager::create($dbParams, $config);
  3. return $em;

Lanzador.php
Código PHP:
Ver original
  1. ...
  2. require_once $rutaControlador;
  3. $registro = new claseRegistro();
  4. $registro->set('em', include 'DoctrineLanzador.php');
  5. ...

Controller
Código PHP:
Ver original
  1. public function prueba()
  2. {
  3.     $em = $this->_regs->get('em');
  4.     //READ
  5.     $category = $em->find('Entity\Category', 1);
  6.     ....
  7.     $repo       = $em->getRepository('Entity\Category');    
  8.     $categories = $repo->findActiveCategories();
  9.  
  10.     //WRITE
  11.     $category->setName('Custom name');
  12.     $em->persist($category);
  13.     $em->flush();    
  14. }

Custom Repository
Código PHP:
Ver original
  1. namespace Entity\Repository;
  2.  
  3. use Doctrine\ORM\EntityRepository;
  4.  
  5. class CategoryRepository extends EntityRepository
  6. {
  7.      public function getActiveCatgories()
  8.      {...}
  9. }

Category
Código PHP:
Ver original
  1. namespace Entity;
  2.  
  3. use Doctrine\Common\Collections\ArrayCollection;
  4.  
  5. /**
  6.  * @Entity(repositoryClass="Entity\Repository\CategoryRepository")
  7.  * @Table()
  8.  */
  9. class Category
  10. {...}

Saludos.
__________________
http://es.phptherightway.com/
thats us riders :)