I will make it as simple as possible...
I have two entities : Pds and Specialite
Here are the two DbTable class :
class Application_Model_DbTable_Specialite extends Zend_Db_Table_Abstract
{
/**
* @var $_name : Nom de la table dans la BDD
* @var $_primary : Nom de la clé primaire de la table
* @var $_schema : Nom de la BDD
* @var $_adapter : Allias de la BDD dans le registre de Zend (défini dans le Bootstrap)
*/
protected $_name = 'ps_specialite';
protected $_primary = 'ps_spe_id';
protected $_schema = 'basename';
protected $_adapter = 'db_1';
protected $_referenceMap = array(
'Pds' => array(
'columns' => 'numprat_id',
'refTableClass' => 'Pds',
'refColumns' => 'id'
)
);
}
class Application_Model_DbTable_Pds extends Zend_Db_Table_Abstract
{
/**
* @var $_name : Nom de la table dans la BDD
* @var $_primary : Nom de la clé primaire de la table
* @var $_schema : Nom de la BDD
* @var $_adapter : Allias de la BDD dans le registre de Zend (défini dans le Bootstrap)
*/
protected $_name = 'ps_praticiens';
protected $_primary = 'numprat_id';
protected $_schema = 'basename';
protected $_adapter = 'db_1';
protected $_dependentTables = array('Specialite');
}
Here are the two Models :
class Application_Model_Specialite extends Zend_Db_Table_Row_Abstract {
protected $_id;
protected $_id_pds;
protected $_principal;
public function __construct(array $options = null){}
public function __set($name, $value){}
public function __get($name){}
public function setOptions(array $options){}
public function setId($id){}
public function getId(){}
public function setIdPds($id_pds){}
public function getIdPds(){}
public function setPrincipal($principal){}
public function getPrincipal(){} }
class Application_Model_Pds extends Zend_Db_Table_Row_Abstract {
protected $_id;
protected $_nom;
protected $_nom_pro;
protected $_prenom;
[ ... same contruction as Specialite ... ]
}
And my PdsMapper.php :
class Application_Model_PdsMapper { protected $_dbTable;
public function setDbTable($dbTable)
{
if (is_string($dbTable)) {
$dbTable = new $dbTable();
}
if (!$dbTable instanceof Zend_Db_Table_Abstract) {
throw new Exception('Invalid table data gateway provided');
}
$this->_dbTable = $dbTable;
return $this;
}
public function getDbTable()
{
if (null === $this->_dbTable) {
$this->setDbTable('Application_Model_DbTable_Pds');
}
return $this->_dbTable;
}
public function save(Application_Model_Pds $pds){}
public function find($id, Application_Model_Pds $pds)
{
$result = $this->getDbTable()->find($id);
if (0 == count($result)) {
return;
}
$row = $result->current();
$pds->setId($row->id)
->setNom($row->nom)
->setPrenom($row->prenom);
return $pds;
}
public function fetchAll(){} }
The link between Pds and Specialite is :
- Pds have one or several speciality
- Specialite concerns one or several Pds
I want to get the Specialite of a PDS. Here is index action in my controller :
public function indexAction(){
$o_mapper = new Application_Model_PdsMapper();
$pds = $o_mapper->find('69000001', new Application_Model_Pds());
$pds_69000001 = $pds->current();
$specialiteByPds = $pds_69000001->findDependentRowset('Specialite');
$this->view->pds = $pds;
$this->view->specialite = $specialiteByPds;
}
But the application tell me thaht current() method is unrecognized ... I'm looking to make it work since yesterday but I don't see where is the problem...
Thanks in advance