Creating the Base Class
Create a new class in this file named CMS_Content_Item_Abstract. Since this class wraps a standard page, you need to add properties for each of the pages table's columns to it. Make all the fields except namespace public. The namespace field will be set on an item level and should be protected so only child classes can change it. Also, add a protected property for the Page model, which will be loaded in the constructor, so it needs to get loaded only once.
Once you set these up, add the constructor. This should create a new instance of the Page model and set the pageModel property. Then it should load the page if a page ID has been passed to it. Use the loadPageObject() method, which you will create shortly (Listing 5-13).
Listing 5-13. The Base CMS_Content_Item_Abstract Class in library/CMS/Content/Item/Abstract.php <?php abstract class CMS_Content_Item_Abstract {
public $id;
public $name;
protected $_namespace = 'page'; protected $_pageModel;
public function _construct($pageId = null)
$this->_pageModel = new Page(); if(null != $pageId) {
$this->loadPageObject(intval($pageId));
Post a comment