Symfony2 gedmo SortablePosition注释不存在

时间:2014-08-18 12:12:30

标签: php symfony doctrine-orm jquery-ui-sortable behavior

我想使用Gedmo Extensions在doctrine实体中实现可排序的行为。

我的配置:

services:
    # KernelRequest listener
    extension.listener:
        class: {Bundle Name}\Listener\DoctrineExtensionListener
        calls:
            - [ setContainer, [ @service_container ] ]
        tags:
            # translatable sets locale after router processing
            - { name: kernel.event_listener, event: kernel.request, method: onLateKernelRequest, priority: -10 }
            # loggable hooks user username if one is in security context
            - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
    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 ] ]

    gedmo.listener.loggable:
        class: Gedmo\Loggable\LoggableListener
        tags:
            - { name: doctrine.event_subscriber, connection: default }
        calls:
            - [ setAnnotationReader, [ @annotation_reader ] ]

实体:

namespace Stenik\FooterLinkBundle\Entity;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
// use Gedmo\Translatable\TranslationInterface as Translatable;
// use Gedmo\Mapping\Annotation\SortablePosition as SortablePosition;

/**
 * @ORM\Table(name="footer_link")
 * @ORM\Entity(repositoryClass="Gedmo\Sortable\Entity\Repository\SortableRepository")
 * @Gedmo\Loggable
 */
class FooterLink
{
    use \A2lix\TranslationFormBundle\Util\Gedmo\GedmoTranslatable;

    /**
     * @Gedmo\SortablePosition
     * @ORM\Column(name="position", type="integer")
     */
    private $position;

    /** @ORM\Id @ORM\GeneratedValue @ORM\Column(type="integer") */
    protected $id;

    /**
     * @Gedmo\Translatable
     * @ORM\Column(name="title", type="string", length=255)
     */
    protected $title;

    /**
     * @ORM\Column(name="link", type="string", length=255)
     */
    protected $link;

    /**
     * @ORM\Column(name="target", type="string", length=255)
     */
    protected $target = '_self';

    /**
     * @ORM\Column(name="is_hidden", type="boolean", options={"default" = 0})
     */
    protected $is_hidden;

    /**
     * @Gedmo\Timestampable(on="create")
     * @ORM\Column(name="created_at", type="datetime")
     */
    protected $created_at;

    /**
     * @Gedmo\Timestampable(on="update")
     * @ORM\Column(name="updated_at", type="datetime")
     */
    protected $updated_at;

    /** 
     * @ORM\OneToMany(targetEntity="Stenik\FooterLinkBundle\Entity\FooterLinkTranslation", mappedBy="object", cascade={"persist", "remove"}, indexBy="locale")
     */
    protected $translations;

    public function __construct()
    {
        $this->translations = new ArrayCollection();
    }

    public function getId()
    {
        return $this->id;
    }

    public function getTitle()
    {
        return $this->title;
    }

    public function setTitle($value)
    {
        $this->title = $value;
    }

    public function getLink()
    {
        return $this->link;
    }

    public function setLink($value)
    {
        $this->link = $value;
    }

    public function getTarget()
    {
        return $this->target;
    }

    public function setTarget($value)
    {
        $this->target = $value;
    }

    public function getIsHidden()
    {
        return $this->is_hidden;
    }

    public function setIsHidden($is_hidden)
    {
        $this->is_hidden = $is_hidden;
    }

    public function getCreatedAt()
    {
        return $this->created_at;
    }

    public function setCreatedAt($created_at)
    {
        $this->created_at = $created_at;
    }

    public function getUpdatedAt()
    {
        return $this->updated_at;
    }

    public function setUpdatedAt($updated_at)
    {
        $this->updated_at = $updated_at;
    }


    public function __toString()
    {
        return $this->getTitle() ?: 'n/a';
    }
}

我还在捆绑类中添加了服务作为订阅者:

public function boot(){
    // get the doctrine 2 entity manager
    $em = $this->container->get('doctrine.orm.default_entity_manager');

    // get the event manager
    $evm = $em->getEventManager();
    $sortableListener = new \Gedmo\Sortable\SortableListener;
    $evm->addEventSubscriber($sortableListener);
}

但是当我尝试更新架构时,我收到以下错误:

[Doctrine\Common\Annotations\AnnotationException]                                                                                                                                             
[Semantical Error] The annotation "@Gedmo\Mapping\Annotation\SortablePosition" in property Stenik\FooterLinkBundle\Entity\FooterLink::$position does not exist, or could not be auto-loaded. 

1 个答案:

答案 0 :(得分:3)

经过相当的努力,事实证明我使用的学说扩展版本有一些变化(wip-2.4.0),并且不再有SortablePosition和SortableGroup注释,只有Sortable。修好了。