Is extending Zend_Db_Table to read the Prefix from the Registry a better approach than using Zend_Registry directly?
Extending Zend_Db_Table to read the Prefix from the Registry can be a better approach as it encapsulates the logic within the class itself, making it more modular and easier to maintain. By doing this, the Zend_Db_Table class becomes more self-contained and does not rely directly on the global Zend_Registry, improving code organization and separation of concerns.
class My_Db_Table extends Zend_Db_Table_Abstract
{
protected $_prefix = '';
public function __construct($config = array())
{
if (Zend_Registry::isRegistered('prefix')) {
$this->_prefix = Zend_Registry::get('prefix');
}
parent::__construct($config);
}
public function getTableName()
{
return $this->_prefix . parent::getTableName();
}
}