Set up Gedmo/doctrine-extension good extension for nested set

Publié le par samuel

Development environment :

Symfony 2.1.2
Mac OS X 10.6.8
PhpStorm

With this extension, you can implement a data tree. very useful for repesent different grade level.

Setup:

Check the last version in this page : https://packagist.org/packages/gedmo/doctrine-extensions

In composer.json add this line :

"gedmo/doctrine-extensions": "Last_version"

Currently :

 "gedmo/doctrine-extensions": "v2.3.2"


Finally execute:


php composer.phar update

When the command line is finish, you must configure the extension.

In app/config/config.yml add the line


doctrine:

	dbal:

	# your config here

	orm:

		auto_generate_proxy_classes: %kernel.debug%

		auto_mapping: true

		# only these lines are added additionally

		mappings:

			translatable:

				type: annotation

				alias: Gedmo

				prefix: Gedmo\Translatable\Entity

				# make sure vendor library location is correct

				dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"

			tree:

				type: annotation

				alias: Gedmo

				prefix: Gedmo\Tree\Entity

				dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"

At the end of file, add this :


services:

	gedmo.listener.tree:

		class: Gedmo\Tree\TreeListener

		tags:

			- { name: doctrine.event_subscriber, connection: default }

		calls:

			- [ setAnnotationReader, [ @annotation_reader ] ]

	gedmo.listener.translatable:

		class: Gedmo\Translatable\TranslatableListener

		tags:

			- { name: doctrine.event_subscriber, connection: default }

		calls:

			- [ setAnnotationReader, [ @annotation_reader ] ]

			- [ setDefaultLocale, [ %locale% ] ]

			- [ setTranslationFallback, [ false ] ]

	gedmo.listener.timestampable:

		class: Gedmo\Timestampable\TimestampableListener

		tags:

			- { name: doctrine.event_subscriber, connection: default }

		calls:

			- [ setAnnotationReader, [ @annotation_reader ] ]

	gedmo.listener.sluggable:

		class: Gedmo\Sluggable\SluggableListener

		tags:

			- { name: doctrine.event_subscriber, connection: default }

		calls:

			- [ setAnnotationReader, [ @annotation_reader ] ]

	gedmo.listener.sortable:

		class: Gedmo\Sortable\SortableListener

		tags:

			- { name: doctrine.event_subscriber, connection: default }

		calls:

			- [ setAnnotationReader, [ @annotation_reader ] ]

For finish, you can clear the cache and execute :


php app/console doctrine:mapping:info

and check if you have this line :


[OK]   Gedmo\Translatable\Entity\MappedSuperclass\AbstractPersonalTranslation

[OK]   Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation

[OK]   Gedmo\Translatable\Entity\Translation

[OK]   Gedmo\Tree\Entity\MappedSuperclass\AbstractClosure

Enjoy it !

Cette entrée a été publiée dans Symfony 2 Utils. Vous pouvez la mettre en favoris avec ce permalien.



2 réponses à Set up Gedmo/doctrine-extension good extension for nested set

  1. Julius dit :

    I think this is among the most important info
    for me. And i’m glad reading your article. But want to remark on some general things, The website style is wonderful, the articles is really excellent : D. Good job, cheers

  2. Ping : Symfony2 Gedmo Tree with Translatable listner | User36

Répondre à Julius Annuler la réponse.

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

*


nine * = 45

Vous pouvez utiliser ces balises et attributs HTML : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>