【问题标题】:Symfony Semantical Error as constraintsSymfony 语义错误作为约束
【发布时间】:2014-09-03 19:45:12
【问题描述】:

输入此命令后 (php app/console generate:doctrine:entities CoreBundle:Post ) 通过终端出现以下错误,我该如何解决?

[Doctrine\Common\Annotations\AnnotationException]
[语义错误] 注释 属性中的“@Symfony\Component\Validator\Constraints” Blog\CoreBundle\Entity\Post::$body 不存在,或不能存在 自动加载。

源代码:

namespace Blog\CoreBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Post
 *
 * @ORM\Table()
 * @ORM\Entity
 */
class Post extends Timestamp
{
/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var string
 *
 * @ORM\Column(name="title", type="string", length=255)
 */
private $title;

/**
 * @var string
 *
 * @ORM\Column(name="body", type="text")
 *
 * @Assert|NotBlank
 */
private $body;


/**
 * @var Author
 *
 * @ORM\ManyToOne(targetEntity="Author", inversedBy="posts")
 * @ORM\JoinColumn(name="author_id", referecedColumnName="id", nullable=false)
 */
protected  $author;


/**
 * Get id
 *
 * @return integer 
 */
public function getId()
{
    return $this->id;
}

/**
 * Set title
 *
 * @param string $title
 * @return Post
 */
public function setTitle($title)
{
    $this->title = $title;

    return $this;
}

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

/**
 * Set body
 *
 * @param string $body
 * @return Post
 */
public function setBody($body)
{
    $this->body = $body;

    return $this;
}

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

}

【问题讨论】:

    标签: symfony doctrine-orm


    【解决方案1】:

    我认为您在$body 属性的@Assert 注释中有错字。您使用的是管道符号 | 而不是反斜杠 \

    【讨论】:

    • 谢谢你的回答@lxg
    • 它解决了您的问题吗?如果是,请接受答案。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-07
    • 2011-10-04
    • 2019-09-22
    相关资源
    最近更新 更多