小编Dua*_*ran的帖子

从请求中填充实体的更好方法是什么?

我正在使用Symfony 2.1应用程序,我有很多参数通过POST请求发送,我正在寻找一种更智能的方法来获取每个请求参数并填充我的实体类.我希望避免$entity->setMyParam($my_param)n请求参数编写表达式.例如,这是我的实体的片段:

namespace Brea\ApiBundle\Entity;

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

/**
 * Brea\ApiBundle\Entity\Distributions
 *
 * @ORM\Table(name="distributions")
 * @ORM\Entity
 */
class Distributions
{
  /**
   * @var string $recordType
   *
   * @ORM\Column(name="record_type", type="string", nullable=false)
   * @Assert\NotBlank()
   * @Assert\Choice(choices = {"a", "b", "c", "d", "e"}, message = "Choose a valid record type")
   */
  private $recordType;

  /**
   * Set recordType
   *
   * @param string $recordType
   */
  public function setRecordType($recordType)
  {
    $this->recordType = $recordType;
  }

  /**
   * …
Run Code Online (Sandbox Code Playgroud)

php doctrine-orm symfony-2.1

6
推荐指数
1
解决办法
2374
查看次数

标签 统计

doctrine-orm ×1

php ×1

symfony-2.1 ×1