Php zend framework 2,带连接的分页器
我正在使用zend framework 2编写,但在使用join分页时遇到了一个问题。 我有一个函数:Php zend framework 2,带连接的分页器,php,join,pagination,zend-framework2,Php,Join,Pagination,Zend Framework2,我正在使用zend framework 2编写,但在使用join分页时遇到了一个问题。 我有一个函数: if ($paginated) { $select = new \Zend\Db\Sql\Select (); $select->from ( 'cliente' ); $select->columns ( array ('*'), false );
if ($paginated) {
$select = new \Zend\Db\Sql\Select ();
$select->from ( 'cliente' );
$select->columns ( array ('*'), false );
$select->join ( 'privato', "cliente.idCliente = privato.idCliente", array ('*'), 'left' );
$select->join ( 'azienda', "cliente.idCliente = azienda.idCliente", array ('*'), 'left' );
$resultSetPrototype = new ResultSet ();
$resultSetPrototype->setArrayObjectPrototype ( new Cliente () );
$paginatorAdapter = new DbSelect (
$select,
$this->tableGateway->getAdapter ());
$resultSetPrototype );
//$paginatorAdapter = $this->tableGateway->selectWith ( $select );
$paginator = new Paginator ( $paginatorAdapter );
return $paginator;
}
$select = new \Zend\Db\Sql\Select ();
$select->from ( 'cliente' );
$select->columns ( array ('*') );
$select->join ( 'privato', "cliente.idCliente = privato.idCliente", array ('*'), 'left' );
$select->join ( 'azienda', "cliente.idCliente = azienda.idCliente", array ('*'), 'left' );
$resultSet = $this->tableGateway->selectWith ( $select );
return $resultSet;
if语句外的代码工作正常,内部代码号显示以下消息:
Statement could not be executed (42S21 - 1060 - Duplicate column name 'idCliente')
错误在哪里?
多谢各位
$select->columns ( array ('idCliente1'=>'idCliente'), false );
是因为您必须提供别名,或者在连接上,您可以通过定义所有您想要的列名称来忽略idCliente,例如:
$select->join ( 'azienda', "cliente.idCliente = azienda.idCliente", array ('column1','column2','etc..'), 'left' );
你试过我的答案了吗?