Orm 表单不会绑定所有数据

Orm 表单不会绑定所有数据,orm,doctrine-orm,zend-framework2,Orm,Doctrine Orm,Zend Framework2,更新 当我使用: public function setUrl_key($value) { $this->url_key = $value; } public function getUrl_key() { return $this->url_key; } 而不是: public function setUrlKey($value) { $this->url_key = $value; } public function getUrlKey() { return $this-

更新

当我使用:

public function setUrl_key($value) { $this->url_key = $value; }
public function getUrl_key() { return $this->url_key; }
而不是:

public function setUrlKey($value) { $this->url_key = $value; }
public function getUrlKey() { return $this->url_key; }
很好。为什么?


将ZF2与条令2一起使用。在我的表单的编辑操作中,只有
标题
电子邮件
字段显示在它们的文本框中。其他文本框为空,就好像数据库中没有值一样。但是有

但是如果我把
url\u键
放进
email
setter/getter,就像下面这样,它就可以工作了

public function setEmail($value) { $this->url_key = $value; }
public function getEmail() { return $this->url_key; }
工作通过电子邮件获取。。。我想我的装订或条令2有问题吧


以下是我的一些代码:

控制器

    $link = $this->getObjectManager()->getRepository('Schema\Entity\Link')->find($this->params('id'));
    $form = new AdminLinkForm($this->getObjectManager());
    $form->setHydrator(new DoctrineEntity($this->getObjectManager(),'Schema\Entity\Link'));
    $form->bind($link);
    $request = $this->getRequest();
    if ($request->isPost()) {
实体(设置器和获取器)


正如您在更新中所注意到的,是您的实体字段/设置器不匹配。 条令发现
受保护的$short\u描述
并尝试查找相应的getter/setter,但
setShortDesc()
不匹配

您应该使用类似于
protected$shortDesc;getShortDesc();setShortDesc()
as原则读取实体字段,然后尝试查找与之前相同名称和前置方法匹配的getter/setter。当仅通过getter内部的代码链接时,无法将
getShortDesc()
short\u description
匹配

在ZF2中,建议您使用camelCase,因此即使在实体中,删除下划线似乎也是一种很好的做法。否则getter看起来不合适,在同一代码中混合两种样式是不好的

如果在表中需要或需要使用下划线,可以这样说:

/**@列(name=“field\u name”)*/


private$fieldName

这正是我使用下划线的原因。希望在数据库字段中有下划线,但不知道(name=“field\u name”)注释。谢谢
.....

/** @ORM\Column(type="string", name="title", length=255, nullable=false) */
protected $title;

/** @ORM\Column(type="string", length=255, nullable=false) */
protected $short_description;

/** @ORM\Column(type="string", length=255, nullable=true) */
protected $image;

/** @ORM\Column(type="text", nullable=true) */
protected $sample_title;

/** @ORM\Column(type="text", nullable=true) */
protected $sample_description;

/** @ORM\Column(type="text", nullable=true) */
protected $sample_keys;

/** @ORM\Column(type="string", name="webpage_url", length=255, nullable=false) */
protected $webpage_url;

/** @ORM\Column(type="string", length=255, nullable=true) */
protected $email;
......

public function setId($value) { $this->link_id = (int)$value; }
public function getId() { return $this->link_id; }

public function setTitle($value) { $this->title = $value; }
public function getTitle() { return $this->title; }

public function setShortDesc($value) { $this->short_description = $value; }
public function getShortDesc() { return $this->short_description; }

public function setUrlKey($value) { $this->url_key = $value; }
public function getUrlKey() { return $this->url_key; }

public function setEmail($value) { $this->email = $value; }
public function getEmail() { return $this->email; }