I am newbie to zend framewrok 2. I am just practicing album application provided by zf2 documentation. After that i create another controller namely PersonalInfo. In PersonalInfo entity i used a properties namely dt which will be not updated by form input. It is updated by default in database. Here is my Entity.
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;
}
I am strange if i not use $this->dt= (!empty($data['dt'])) ? $data['dt'] : null; in exchangeArray method then getDt() method return null but if i use that in exchangeArray method than it returns actual data. In my general understanding i am not clear about the trick of exchangeArray method. It is neccessary to know for me because in future to solve this type of problem.
exchangeArray()method is basically shown to be used for setting the $_POST values to the object properties. (Note: not necessary to be post values always).