On 9/25/06, Stuardo -StR- RodrÃguez <[EMAIL PROTECTED]> wrote:
Hi all, I'm using Zend_Db_Table as a "model" from the MVC, so from the
Controller I load some models wich extend from Zend_Db_table an overload the
update, delete, insert, etc methods from Zend_Db_Table.
I'm working on a CMS (more like a DMS) and I have the "pages" model
class BizMS_Model_Page extends Zend_Db_Table {
protected $_name = 'bizms_page';
[...]
}
Then, I have a static method that returns me the full page-tree of this model.
I thought it should be a static method because I do not need to create a Page
to get them all. so in the controller I could do:
$view = Zend::registry('view');
Zend::loadClass('BizMS_Model_Page');
$view->pageTree = BizMS_Model_Page::getTree();
In my getTree I will execute a query to get all the pages from y page table..
but Zend_Db_Table::$_name is a protected variable...
first I thoght it sould be a static variable, because I cannot use it in my
public static function getTree() because it is a static method.
then I thought, well.. it will never be changed from Page to Page, so.. why
isn't it a Class constant?
Any ideas? thanks :D
Making it a class constant would make it impossible to change it
mid-stream, which would be useful; making it static would. And you
*would* be able to grab it via a static method:
public static method getTree()
{
echo self::$_name;
}
However, that's water under the bridge for now; you need to be able to
access it from an object instance. What I've done when using
Zend_Db_Table is to create an accessor for the name and primary key:
public function getName()
{
return $this->_name;
}
public function getPrimary()
{
return $this->_primary;
}
--
Matthew Weier O'Phinney
PHP Developer | [EMAIL PROTECTED]
Zend Technologies | http://www.zend.com/