Symfony语义错误

时间:2015-05-28 10:05:57

标签: php symfony

我收到此错误:(在一切正常之前,但经过一些更改后才开始出现)

  

[语义错误]注释" @Expose"在属性VswSystem \ CmsBundle \ Entity \ Slider :: $ name从未导入。

     

您是否忘记添加"使用"这个注释的陈述?

代码在这里:

<?php

namespace VswSystem\CmsBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use VswSystem\CmsBundle\Entity\SliderImage;
use Doctrine\Common\Collections\ArrayCollection;
use VswSystem\CmsBundle\Entity\Traits\IdentificationalEntity;
use VswSystem\CmsBundle\Entity\Traits\NamedEntity;
use JMS\Serializer\Annotation\Expose;

/**
 * Slider
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="VswSystem\CmsBundle\Entity\Repository\SliderRepository")
 * @ORM\HasLifecycleCallbacks()
 */
class Slider
{
    use IdentificationalEntity;
    use NamedEntity;

    /**
     * @var SliderImage
     * @ORM\ManyToMany(targetEntity="SliderImage", cascade={"persist"}, orphanRemoval=true)
     * 
     */
    protected  $slides;

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


    /**
     * Get all slides
     * @return ArrayCollection
     */
    public function getSlides()
    {
        return $this->slides;
    }

}

NamedEntity文件代码:

<?php
namespace VswSystem\CmsBundle\Entity\Traits;

use Symfony\Component\Validator\Constraints as Assert;


/**
 * Class NamedEntity
 * @package VswSystem\CmsBundle\Entity\Traits
 */
trait NamedEntity
{
    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=255, nullable=true)
     * @Assert\NotBlank
     * @Assert\Length(min="3")
     * @Expose
     */
    protected $name;


    /**
     * Set name
     *
     * @param string $name
     * @return File
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }
}

不能弄清楚出了什么问题......

1 个答案:

答案 0 :(得分:4)

错误消息正好指出具体错误。

您需要在$ name字段定义中省略@Expose注释,或添加use语句,其中添加指向Expose类的链接。

如果您使用JMS Serializer包中的Expose,则应添加下一行:

use JMS\Serializer\Annotation\Expose;