How to use multiple table use in single model in zf2?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to use multiple table use in single model in zf2?

jekin1991
This post has NOT been accepted by the mailing list yet.
Hello,
I have one problem. I don't know how to use multiple table and join query in zf2.
I'm using service Manager and TableGateway for model.but in this it always use single table.
how can i use multiple table in single controller or model.
Here i'm using Module.php file and configure table gateway.
when i add another table gateway then it gives me errors.

public function getServiceConfig()
    {
        return array(
            'factories' => array(
                'Employee\Model\EmployeeTable' =>  function($sm) {
                    $tableGateway = $sm->get('EmployeeTableGateway');
                    $table = new EmployeeTable($tableGateway);
                    return $table;
                },
                'EmployeeTableGateway' => function ($sm) {
                    $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                    $resultSetPrototype = new ResultSet();
                    $resultSetPrototype->setArrayObjectPrototype(new Employee());
                    return new TableGateway('employee', $dbAdapter, null, $resultSetPrototype);
                },
                        ),
        );
    }
Please reply me as soon as possible.I need argent help.
Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: How to use multiple table use in single model in zf2?

samsonasik
This post has NOT been accepted by the mailing list yet.
 maybe something tricky like this :
 
    public function fetchJoin()
    {
        $select = new \Zend\Db\Sql\Select ;
        $select->from('province');
        $select->columns(array('province'));
        $select->join('village', "village.id_province = province.province.id", array('village'), 'left');
         
        echo $select->getSqlString();
        $resultSet = $this->tableGateway->selectWith($select);
       
        return $resultSet;
    }
Reply | Threaded
Open this post in threaded view
|

Re: How to use multiple table use in single model in zf2?

jekin1991
This post has NOT been accepted by the mailing list yet.
Thank you samsonasik, it's work.