Skip to content

Instantly share code, notes, and snippets.

@arth2o

arth2o/Doctrine Cheatsheet

Last active Jul 23, 2016
Embed
What would you like to do?
Doctrine Cheatsheet
Doctrine generate entity/entities from database:table
php app/console doctrine:mapping:import --force GleamPageBundle xml
php app/console doctrine:mapping:convert annotation ./src
php app/console doctrine:generate:entities GleamPageBundle
Creating the Database Tables/Schema
php app/console doctrine:schema:update --force
------------------------
Save Elements:
$product = new Product();
$product->setName('A Foo Bar');
$product->setPrice('19.99');
$product->setDescription('Lorem ipsum dolor');
$em = $this->getDoctrine()->getManager();
$em->persist($product);
$em->flush();
------------------------
GetRepository:
$repository = $this->getDoctrine()->getRepository('AcmeStoreBundle:Product');
------------------------
Find:
$product = $repository->find($id);
// dynamic method names to find based on a column value
$product = $repository->findOneById($id);
$product = $repository->findOneByName('foo');
// find *all* products
$products = $repository->findAll();
// find a group of products based on an arbitrary column value
$products = $repository->findByPrice(19.99);
------------------------
Debug Ductrine
exit(\Doctrine\Common\Util\Debug::dump($yourDoctrineResult));
------------------------
@htxuankhoa

This comment has been minimized.

Copy link

@htxuankhoa htxuankhoa commented Jul 23, 2016

Thanks @arth2o 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.