How can I get data from another table in a Zend_Db model class?
Yes, it is possible to instantiate another table class inside the methods of another table class.
But if you have an application work that includes multiple tables, it is better to create a class that encapsulates that application and use both tables from it.
This is why it is inaccurate to call a table a model. Nowhere in the documentation Zend_Db_Table
does it call the table as a model.
A model is a part of your application and may require multiple tables to do its job. The class corresponding to your table is a table.
Divide your models from your tables!
Repeat your comment: you still think the model is expanding Zend_Db_Table_Abstract
- it is not!
Model is not a data access class, it is a unit of your application. It does not cover any part of the Zend Framework.
The relationship between model and table is HAS-A, not IS-A.
class MyRegistryModel // extends nothing
{
/**
* @var Zend_Db_Table_Abstract
*/
protected $_registryTable;
/**
* @var Zend_Db_Table_Abstract
*/
protected $_namesTable;
public function __construct()
{
$this->_registryTable = new RegistryTable();
$this->_namesTable = new NamesTable();
}
public function getDailyReport()
{
// use the tables as needed to build the report
}
}
a source to share