Reputation: 453
I would like to ask you how it si possible to implement the sortable repository for gedmo sortable extension into symfony 2. I am a little confused how to inject the EntityManager and ClassMetadata into the constructor and how the repository register correctly in services.yml and entity.
Here is the repository: https://github.com/l3pp4rd/DoctrineExtensions/blob/master/lib/Gedmo/Sortable/Entity/Repository/SortableRepository.php
Thank you very much!
Upvotes: 0
Views: 2127
Reputation: 943
Remember to subscribe GedmoListener on boot()
<?php
class AcmeBundle extends Bundle
{
$em = $this->container->get('doctrine.orm.default_entity_manager');
$evm = $em->geteventmanager();
$evm->addeventsubscriber(new \gedmo\sortable\sortablelistener);
}
Upvotes: 0
Reputation: 4092
I recommend you install the StofDoctrineExtensionsBundle
And you can enable the sortable behavior in your config file.
Example:
config.yml
stof_doctrine_extensions:
orm:
default:
sortable: true
Entity class
/**
* Acme\Bundle\ProjectBundle\Entity\Foo
*
* @ORM\Table
* @ORM\Entity(repositoryClass="Gedmo\Sortable\Entity\Repository\SortableRepository")
*/
class Foo
{
/**
* @var integer $position
*
* @Gedmo\SortablePosition
* @ORM\Column(name="position", type="integer")
*/
private $position;
}
Upvotes: 2