【发布时间】:2014-05-14 06:26:03
【问题描述】:
我是zend framewrok 2的新手。我只是在练习zf2文档提供的相册应用程序。之后我创建了另一个控制器,即 PersonalInfo。在 PersonalInfo 实体中,我使用了一个属性,即 dt,它不会被表单输入更新。它默认在数据库中更新。这是我的实体。
class PersonalInfo {
protected $id;
protected $name;
protected $fName;
protected $email;
protected $picture;
protected $dt;
public function exchangeArray($data) {
$this->id = (!empty($data['id'])) ? $data['id'] : null;
$this->name = (!empty($data['name'])) ? $data['name'] : null;
$this->fName = (!empty($data['fName'])) ? $data['fName'] : null;
$this->email = (!empty($data['email'])) ? $data['email'] : null;
$this->picture = (!empty($data['picture'])) ? $data['picture'] : null;
}
// Add the following method:
public function getArrayCopy() {
return get_object_vars($this);
}
public function getId() {
return $this->id;
}
public function setId($id) {
$this->id = $id;
}
public function getName() {
return $this->name;
}
public function setName($name) {
$this->name = $name;
}
public function getFName() {
return $this->fName;
}
public function setFName($fName) {
$this->fName = $fName;
}
public function getEmail() {
return $this->email;
}
public function setEmail($email) {
$this->email = $email;
}
public function getPicture() {
return $this->picture;
}
public function setPicture($picture) {
$this->picture = $picture;
}
public function getDt() {
return $this->dt;
}
public function setDt($dt) {
$this->dt = $dt;
}
如果我不使用 $this->dt= (!empty($data['dt'])) 我很奇怪? $data['dt'] : null;在 exchangeArray 方法中 getDt() 方法返回 null 但如果我在 exchangeArray 方法中使用它而不是返回实际数据。在我的一般理解中,我不清楚 exchangeArray 方法的技巧。我有必要知道,因为将来要解决这类问题。
【问题讨论】:
-
参考文档,
exchangeArray()方法基本上用于将 $_POST 值设置为对象属性。 (注意:不必总是发布值)。
标签: php zend-framework2