2014-01-24 29 views
0

UPDATE形式不绑定的所有数据

当我使用:

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.在我的形式的编辑操作仅领域titleemail显示在他们的文本框中。其他文本框是空的,就好像数据库中没有值一样。但是还有。

但是,如果我把url_key例如email setter/getter像下面它的工作。

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

通过电子邮件getter工作...我想我的约束力或教条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()) { 

实体(setter方法&干将)

..... 

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

回答

1

这是你的实体网络如您在更新中记录的字段/设置器不匹配。 学说发现protected $short_description;并试图找到相应的getter/setter,但setShortDesc()不匹配。

您应该使用类似protected $shortDesc; getShortDesc(); setShortDesc();这样的规则作为原则读取实体字段,然后尝试查找匹配相同名称和前置方法的getters/setters。当它仅通过getter内部的代码链接时,不可能匹配getShortDesc()short_description

在ZF2中,我们建议您使用camelCase,因此即使在实体中,它似乎也是一种很好的做法,可以摆脱下划线。否则,getter将看起来不合适,并且混合使用相同代码中的两种样式并不好。

如果你的表有你想要或需要使用下划线,你可以告诉原则是这样的:

/** @Column(name="field_name") */

private $fieldName;

+0

这就是为什么我使用下划线。希望在数据库字段中有下划线,并且不知道(name =“field_name”)注释。谢谢 – Nikitas