Skip to content
William Espindola edited this page Sep 10, 2015 · 5 revisions

If the Repository is not enough for you, you can work with storage make other things as you need with native method of Doctrine or Relational ORM.

Doctrine

use Doctrine\ORM\Tools\Setup;
use WilliamEspindola\Field\Storage\ORM\Doctrine;

$conn            = ['driver' => '', 'user' => '', 'dbname' =>  '', 'password' => ''];
$configXml       = __DIR__ . "vendor/williamespindola/field/config/xml";
$setUp           = Setup::createXMLMetadataConfiguration([$configXml], true);
$storage         = new Doctrine($yourConnection, $setUp);

Repository

$storage->setRepository('WilliamEspindola\Field\Entity\Field');
$repository = $this->getRepository();

// Then you can work with native method os Doctrine
$repository->find($id);

EntityManager

The getMapper method give you the EntityManager central access point to ORM functionality

$entityManager = $storage->getMapper();

// example native find doctrine method
$field = $entityManager->find('WilliamEspindola\Field\Entity\Field', $id);
// example native query doctrine method
$query = $entityManager->createQuery('SELECT f FROM WilliamEspindola\Field\Entity\Field f WHERE f.id > 10');
$fields = $query->getResult();

Relational

use Respect\Relational\Mapper;
use WilliamEspindola\Field\Storage\ORM\RespectRelational;

$mapper          = new Mapper(new PDO(/* string connection */));
$storage         = new RespectRelational($mapper);

Mepper work with fluid interface, so if you are using it you just need it and work like this:

$fields = $mapper->field[$id]->fetch();
$allFields = $mapper->field->fetchAll();

Repository

But if you want the repository of field directly you can work like this

$storage->setRepository('WilliamEspindola\Field\Entity\Field');
$repository = $this->getRepository();

// Then you can work with native method of Relational
$repository[$id]->find($id);
// the same example using concret instead fluid 
$repository->setCondition(['id' => $id]);
$repository->find($id);
Clone this wiki locally