Modeling objects with multiple table relationships in Zend Framework ?

Answer

classUsersextendsZend_Db_Table_Abstract{protected $_name ='users';protected $_rowClass ='User';protected $_dependentTables = array ('UserMetadata','UserPassword');...classUserMetadataextendsZend_Db_Table_Abstract{protected $_name ='user_metadata';protected $_referenceMap = array ('Users'=> array ('columns'=>'user_id','refTableClass'=>'Users','refColumns'=>'id'));...classUserPasswordextendsZend_Db_Table_Abstract{protected $_name ='user_password';protected $_referenceMap = array ('Users'=> array ('columns'=>'user_id','refTableClass'=>'Users','refColumns'=>'id'));

Fetching data:

$id =//get your user id from somewhere

$users =newUsers();
$user = $users->fetchRow('id=?', $id);if($user->authMethod ==0){
    $metadata = $user->findDependentRowset('UserMetadata')->current();}

or

$user = $users->fetchRow($users->select()->where('gender=?, 'M')
              ->order('email ASC');

... etc.

Inserting data:

$newRow = $users->fetchNew();
$newRow->email = me@domain.com;
$newRow->save();

or

$users =newUsers();
$data = array('email'=>'me@domain.com','firstname'=>'Me');
$users->insert($data);

Updating:

$user->email ='me@domain.org';
$user->save();

Deleting a row:

$user->delete();

Using transaction:

$db->beginTransaction();
$db->commit();
$db->rollback();

All zend-framework Questions

Ask your interview questions on zend-framework

Write Your comment or Questions if you want the answers on zend-framework from zend-framework Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---