I am using the Zend Framework databases classes as the base for database abstraction in my application. I would like to be able to retrieve a table name from its table class statically, without having to instance the class.
As it's structured, the Zend_Db_Table class has the $_name property to declare the table name. I've created an alternative static $_tableName property in my extending class that basically carries the same information.
I tried modifying the constructor in such a way that the new $_tableName property would overwrite the $_name property if is set, allowing me to replace the $_name property with my static $_tableName property without having redundant properties. i.e:
Code: Select all
//Adding the static property to Zend_Db_Table
class My_Db_Table extends Zend_Db_Table
{
public static $_tableName = null;
public __construct($config = array())
{
if(is_string(self::$_tableName)){
$this -> _name = self::$_tableName;
}
parent::__construct($config);
}
}
//Declaring a concrete table class
class FilesTable extends My_Db_Table
{
public static $_tableName = 'files';
}
$filesTable = new FilesTable(); //Fails. Throws exception 'Table doesn't exist'
Is there a way around this? To still provide static access to the table name without having two properties ($_name and $_tableName) containing the same data?