0
我試圖覆蓋論壇包的實體驗證。 我不喜歡這樣寫道:symfony註釋驗證覆蓋實體/模型
分類實體:
//src/MSD/ForoBundle/Entity/Category.php
namespace MSD\ForoBundle\Entity;
use Herzult\Bundle\ForumBundle\Entity\Category as BaseCategory;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="Herzult\Bundle\ForumBundle\Entity\CategoryRepository")
*/
class Category extends BaseCategory
{
}
主題實體:
//src/MSD/ForoBundle/Entity/Topic.php
namespace MSD\ForoBundle\Entity;
use Herzult\Bundle\ForumBundle\Entity\Topic as BaseTopic;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Topic
*
* @ORM\Entity(repositoryClass="Herzult\Bundle\ForumBundle\Entity\TopicRepository")
*
*/
class Topic extends BaseTopic
{
/**
* @ORM\ManyToOne(targetEntity="Category")
*/
protected $category;
/**
* @Assert\NotBlank()
* @Assert\MinLength(limit=4, message="Just a little too short| ")
* @Assert\Regex(
* pattern="/^[a-zA-Z0-9\-_¿?!¡ ]{4,50}$/",
* message="El tema puede contener letras, números, guiones y espacios, interrogantes y exclamaciones. Entre 4 y 30 caracteres"
*)
*/
protected $subject;
/**
* {@inheritDoc}
*/
public function getAuthorName()
{
return $this->author;
}
/**
* @ORM\ManyToOne(targetEntity="User")
*/
private $author;
public function setAuthor(User $user)
{
$this->author = $user;
}
public function getAuthor()
{
return $this->author;
}
}
郵政實體:
//src/MSD/ForoBundle/Entity/Post.php
namespace MSD\ForoBundle\Entity;
use Herzult\Bundle\ForumBundle\Entity\Post as BasePost;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="Herzult\Bundle\ForumBundle\Entity\PostRepository")
*/
class Post extends BasePost
{
/**
* @ORM\ManyToOne(targetEntity="Topic")
*/
protected $topic;
/**
* @Assert\Regex(
* pattern="/^[^<>]{4,1000}$/",
* message="El mensaje no puede contener '<' ni '>'. Entre 4 y 1000 caracteres"
*)
*
*/
public $message;
public function getAuthorName()
{
return $this->author;
}
/**
* @ORM\ManyToOne(targetEntity="User")
*/
private $author;
public function setAuthor(User $user)
{
$this->author = $user;
}
public function getAuthor()
{
return $this->author;
}
}
和驗證工作......除了消息的溫和派!這是在創建新主題時創建的。 我已經嘗試了很多更改,但沒有成功。 任何想法爲什麼它會發生?
謝謝
是啊!我知道了。解決方案是將此行放在Topic實體中: – Manolo