Skip to content

Instantly share code, notes, and snippets.

@arth2o
Last active July 23, 2016 17:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arth2o/72a2baae0a099db9cab3 to your computer and use it in GitHub Desktop.
Save arth2o/72a2baae0a099db9cab3 to your computer and use it in GitHub Desktop.
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
Copy link

Thanks @arth2o 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment