我用zend框架2编写,但是当我使用分页加入时我遇到了问题。 我有这个功能:
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')
错误在哪里? 非常感谢你
答案 0 :(得分:0)
$select->columns ( array ('idCliente1'=>'idCliente'), false );
是因为您必须提供别名,或者在连接上,您可以通过定义所需的所有列名来忽略idCliente:
$select->join ( 'azienda', "cliente.idCliente = azienda.idCliente", array ('column1','column2','etc..'), 'left' );