Reputation: 67888
I am looking at the quickstart and wondering how these following values are set in the model:
protected $_comment
protected $_created;
protected $_email;
protected $_id;
http://framework.zend.com/manual/en/learning.quickstart.create-model.html
I am not sure if they are automatically set. I see the setters, but I don't know where is it called. Do these variables have to be the same as the database's field names? Are they automatically set? If so, where? I want to read more about the models and conventions, but I couldn't find what I was looking for.
Upvotes: 3
Views: 149
Reputation: 69967
In the Quickstart application, those variables are set by the setter methods in the model class, and those setters are called by the model mapper classes.
Those variables don't have to have any relation to the names of your database columns, but often it is helpful to name them the same or similar to avoid confusion.
The quickstart app uses the Table Data Gateway Pattern that uses the Mapper classes to actually interact with the database. The mapper classes then map data from the database into PHP objects that need not have any knowledge of the database structure or column names.
See this code from GuestbookMapper.php which actually interacts with the database:
public function find($id, Application_Model_Guestbook $guestbook)
{
$result = $this->getDbTable()->find($id);
if (0 == count($result)) {
return;
}
$row = $result->current();
$guestbook->setId($row->id)
->setEmail($row->email)
->setComment($row->comment)
->setCreated($row->created);
}
In the function find(), you pass a Application_Model_Guestbook object, which could be unpopulated, and it maps the database columns to the object (i.e. $row->email, where email IS the name of the database table column).
Now in PHP you can use the Application_Model_Guestbook object to get or set values, and then pass it back to the mapper, which is responsible for updating the appropriate database columns for the record in question.
So to answer your question, No, they are not automatically set, but are set by the mapper class.
Hope that helps, feel free to comment if there is anything else I can answer.
Upvotes: 4