Hello ladies and gentlemen!
I'm new to php and zend framework and fill very uncertain about following:
For example, I have two tables:
table1: box(id, height, width, length, weight)
table2: labels(id, boxid, text, position)
labels.boxid -> box.id
(labels.boxid is a foreign_key for primary_key box.id)
I've generated two separate standard Zend_Db_Table_Abstract+Model+Mapper classes for both tables, which contains all set,get,fetchAll,fetchList methods.
The question: is it safe to extend Box Model to LabeledBox Model classes like this:
class NS_Model_LabeledBox extends NS_Model_Box {
protected $_labels;
public function setLabels($objs)
{
$this->_labels=$objs;
return $this;
}
public function getLabels()
{
return $this->_labels;
}
public function getMapper()
{
if (null === $this->_mapper) {
$this->setMapper(new NS_Model_LabeledBoxMapper());
}
return $this->_mapper;
}
}
along with Mapper classes like this:
class NS_Model_LabeledBoxMapper extends NS_Model_BoxMapper {
public function fetchAll()
{
$resultSet = $this->getDbTable()->fetchAll();
$entries = array();
foreach ($resultSet as $row) {
$entry = new NS_Model_Box();
...setting box properties code...
//fetching and setting labels for the box
$labels = new NS_Model_Labels();
$entry->setLabels(
$labels->fetchList("boxid='" . $row->id . "'")
);
}
$entries[] = $entry;
}
}
so that i can finally run:
$labeledbox = new NS_Model_LabeledBox();
$entries = $labeledbox->fetchAll();
foreach($entries as $entry)
{
echo $entry->getId();
echo $entry->getWeight();
foreach($entry->getLabels() as $lables)
{
echo $lables->getText();
}
}
This code ran fine for me. I just don't want to be left behind if there comes new release of ZF with any significant changes that can possible affect this "trick" (it still applies to OOP paradigm).
Thank you in advance for any preventive(or not) comment on this.