0

フォーラム バンドルのエンティティ検証をオーバーライドしようとしています。私はこのようにします:

カテゴリ エンティティ:

//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;
}
}

そして、検証は機能します...最初の投稿のメッセージを除いて!! これは、新しいトピックが作成されたときに作成されます。私は多くの変更を試みましたが、成功しませんでした。なぜそれが起こったのですか?

ありがとうございました

4

1 に答える 1

0

うん!わかった。解決策は、これをトピック エンティティに追加することでした。

/**
 * @Assert\NotBlank
 * @Assert\Valid
 */
protected $firstPost;

次に、最初の投稿のメッセージが検証されます。

于 2013-07-16T08:11:51.273 に答える