MVC Broker ?

17 views
Skip to first unread message

Yannick ANSQUER

unread,
Nov 16, 2011, 3:08:06 AM11/16/11
to Zend Framework Developers
Hi

I'am new user of ZF

I use a hasone relation in my models

Got Clients which extends Db_Table_Abstract defined like that :
protected $_name = 'clients';
protected $_rowClass = 'Admin_Model_Row_Client';
protected $_primary = 'idClient';

protected $_referenceMap = array(
'Users' => array(
'columns' => 'idUser',
'refTableClass' => 'Admin_Model_DbTable_Users',
'refColumns' => 'idUser'
)
);

Row model for client which get a user :

public function getUser()
{
if (!$this->user) {
$this->user = $this->findParentRow('Admin_Model_DbTable_Users');
}
return $this->user;
}

And in the users model :

protected $_name = 'users';
protected $_primary = 'idUser';
protected $_dependentTables = array('Admin_Model_DbTable_Clients');

Then in the controller I do something like that :

public function readAction()
{
$id = $this->getRequest()->getParam('id');
$clients = new Admin_Model_DbTable_Clients();
$this->view->client = $clients->find($id)->current();
}

And display in the view :

echo $this->client->getUser()->name;

Is this broking MVC structure or is this a good way to display
relations in view ?

Thanks
Reply all
Reply to author
Forward
0 new messages