【问题标题】:How to make Doctrine hydrator populate the entity?如何使 Doctrine hydrator 填充实体?
【发布时间】:2014-03-17 19:23:54
【问题描述】:

这是我目前所拥有的,

表格:

use DoctrineModule\Stdlib\Hydrator\DoctrineObject as Hydrator;
class UserRegisterForm extends
Form implements InputFilterProviderInterface
{
    public function __construct($entityManager)
    {
        parent::__construct('Practitioner');

        $this
            ->setAttribute('method', 'post')
            ->setHydrator(new Hydrator($entityManager), 'App\Entity\Users', true)
            ->setObject(new Users())
        ;

        // add fields here ...
    }
}

控制器:

class UsersController extends AbstractActionController {

public function addAction()
{
    $request = $this->getRequest();
    $form = new PractitionerRegisterForm($this->getEntityManager());
    $users = new \App\Entity\Users;
    $form->bind($users);

    if ( $request->isPost() ) {
        $form->setData($request->getPost());
        // echo pre var_dump($this) /pre
        $users->getDetails();
    } else {
        // do something here
    }

    return ['form' => $form];
}

但我从 $users->getDetails() 得到的是带有 NULL 的属性

那么如何使用 Hydrator 填充实体用户?

【问题讨论】:

    标签: zend-framework orm doctrine-orm


    【解决方案1】:

    解决方案:我必须使用$form->isValid() 来验证表单,该$form->isValid() 验证然后水合(填充)实体。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-02
      • 1970-01-01
      • 1970-01-01
      • 2016-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多