# Annotation reference Bellow you will find all annotation descriptions used in these extensions. There will be introduction on usage with examples. For more detailed usage on extensions, refer to their specific documentation. [blog_reference]: http://gediminasm.org/article/annotation-reference-for-extensions "Doctrine2 extensions annotation reference and examples" Content: - Best [practices](#setup) for setting up - [Tree](#tree) - [Translatable](#translatable) - [Sluggable](#sluggable) - [Timestampable](#timestampable) - [Loggable](#loggable) ## New annotation mapping Recently there was an upgrade made for annotation reader in order to support more native way for annotation mapping in **common2.1.x** branch. Before that you had to make aliases for namespaces (like __gedmo:Translatable__), this strategy was limited and errors were not self explanatory. Now you have to add a **use** statement for each annotation you use in your mapping, see example bellow: ``` php namespace MyApp\Entity; use Gedmo\Mapping\Annotation as Gedmo; // this will be like an alias before use Doctrine\ORM\Mapping\Id; // includes single annotation use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @Gedmo\TranslationEntity(class="something") */ class Article { /** * @Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @Gedmo\Translatable * @Gedmo\Sluggable * @ORM\Column(length=64) */ private $title; /** * @Gedmo\Slug * @ORM\Column(length=64, unique=true) */ private $slug; } ``` **Note:** this new mapping applies only if you use **doctrine-common** library at version **2.1.x** or higher extension library still supports old mapping styles if you manually set the mapping drivers ## Best practices for setting up with annotations {#setup} New annotation reader does not depend on any namespaces, for that reason you can use single reader instance for whole project. The example bellow shows how to setup the mapping and listeners: **Note:** using this repository you can test and check the [example demo configuration](https://github.com/l3pp4rd/DoctrineExtensions/blob/master/example/em.php) ``` php $reader = new \Doctrine\Common\Annotations\AnnotationReader(); $annotationDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader); Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace( 'Gedmo\\Mapping\\Annotation', 'path/to/gedmo/extension/library' ); $chain = new \Doctrine\ORM\Mapping\Driver\DriverChain; $annotationDriver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver($annotationReader, array( __DIR__.'/../your/application/source/Entity', 'path/to/gedmo/extension/library'.'/Gedmo/Translatable/Entity', 'path/to/gedmo/extension/library'.'/Gedmo/Loggable/Entity', 'path/to/gedmo/extension/library'.'/Gedmo/Tree/Entity', )); // drivers $driverChain->addDriver($annotationDriver, 'Gedmo\\Translatable\\Entity'); $driverChain->addDriver($annotationDriver, 'Gedmo\\Loggable\\Entity'); $driverChain->addDriver($annotationDriver, 'Gedmo\\Tree\\Entity'); $driverChain->addDriver($annotationDriver, 'Entity'); $config->setMetadataDriverImpl($driverChain); $config = new \Doctrine\ORM\Configuration(); $config->setMetadataDriverImpl($chain); $config->setProxyDir(/*location*/); $config->setProxyNamespace('Proxy'); $config->setAutoGenerateProxyClasses(false); $evm = new \Doctrine\Common\EventManager(); $translatable = new \Gedmo\Translatable\TranslationListener(); $translatable->setAnnotationReader($reader); $evm->addEventSubscriber($translatable); $tree = new \Gedmo\Tree\TreeListener; $tree->setAnnotationReader($reader); $evm->addEventSubscriber($tree); //... $conn = array( 'driver' => 'pdo_mysql', 'host' => '127.0.0.1', 'dbname' => 'test', 'user' => 'root', 'password' => '' ); $em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm); ``` **Note:** that symfony2 StofDoctrineExtensionsBundle does it automatically this way you will maintain a single instance of annotation reader. It relates only to doctrine-common-2.1.x branch and newer. ## Tree annotations {#tree} Tree can use diferent adapters. Currently **Tree** extension supports **NestedSet** and **Closure** strategies which has a difference for annotations used. Note, that tree will automatically map indexes which are considered necessary for best performance. ### @Gedmo\Mapping\Annotation\Tree (required for all tree strategies) **class** annotation Is the main identificator of tree used for domain object which should **act as Tree**. **options:** - **type** - (string) _optional_ default: **nested** example: ``` php