Zend Framework Handle One to Many

Posted by user192344 on Stack Overflow See other posts from Stack Overflow or by user192344
Published on 2010-04-09T10:26:29Z Indexed on 2010/04/10 10:23 UTC
Read the original article Hit count: 208

Filed under:

I have 2 tables "user", "contact", the relation between two tables is one user has many contact

Table member 
m_id
name
------------
Table Contact
c_id
c_m_id
value

in zend model class, i do it in this way

/* Member.php */
     class Default_Model_DbTable_Member extends Zend_Db_Table_Abstract
     {
        protected $_name    = 'member';
        protected $_dependentTables = array('Default_Model_DbTable_Contact');
     }

/* Contact.php */
     class Default_Model_DbTable_Contact extends Zend_Db_Table_Abstract
     {
        protected $_name = 'contact';
        protected $_referenceMap = array(
                           'Member' => array(
                                    'columns'=> array('c_id'),
                                    'refTableClass'=> 'Default_Model_DbTable_Member',
                                    'refColumns'=> array('c_m_id')
                                   )       
    );
/* IndexController.php */
class IndexController extends Zend_Controller_Action
{
    public function indexAction()
    {   
        $m= new Default_Model_DbTable_Member();
        $row = $m->find(1);
        $data = $row->current();
        $data = $data->findDependentRowset('Default_Model_DbTable_Contact');
        print_r($data->toArray());
     }
}

But i just get Invalid parameter number: no parameters were bound , my goal is to search a member detail record, and it also contains a array which store all contact info (i can use join method to do that, but i just want to try zend feature)

© Stack Overflow or respective owner

Related posts about zend-framework