views:

64

answers:

1

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.

+1  A: 

You do bring up a good point about hitting a moving target, and so far Zend Framework has been that. I started two different projects on ZF 1.7.x and have already re-written some classes due to changes in ZF. Of course, that was more of a desire to stay up-to-date with the "stable" release of ZF, so I didn't really have to.

Zend Framework is certainly a fast-moving framework, and that is something that you need to consider as you write your code, especially since there is talk of breaking backwards compatibility when 2.0.x is released.

borodimer