Reputation: 10056
So this is how my startup model looks like:
<?php
class Test extends Zend_Db_Table{
protected $_name = 'test';
/**
*
* @staticvar Test $instance
* @return Test
*/
static public function getInstance() {
static $instance;
if (!($instance instanceof Test)) {
$instance = new Test();
$instance->init();
}
return $instance;
}
}
So everytime I want to use it in my controller I will have to create it $var = Test::getInstance();
is there a way to extend Zend_Controller to automate this? I mean I don't want to do this everytime in my controller, I just want to use $var->foo
So can I instantiate in a plugin or so that extends Zend_Controller? Or has someone a better idea?
Upvotes: 0
Views: 131
Reputation: 2673
Maybe you have a good reason to extend your class from Zend_Db_Table
instead of Zend_Db_Table_Abstract
, but the latter is usually the most common way of doing it. And it doesn't force you to call getInstance()
, you can just pass the DB adapter to it as a parameter to the constructor.
You can find more information here: http://framework.zend.com/manual/en/zend.db.table.html#zend.db.table.defining
Hope that helps,
Upvotes: 1