2014-01-24 73 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