zf2 paginator with join Exception

时间:2014-07-28 13:18:34

标签: php mysql zend-framework zend-framework2 zend-db

当我使用分页加入时,我遇到了问题。我有这个功能

AllowanceApprovalTable.php

    public function fetchAll($paginated = false) {
        if ($paginated) {
            // create a new Select object for the table album
            $select = new Select('approval_for_allowances');
            $select->columns(array('*'), false);
            $select->join('institutes', 'institutes.id=approval_for_allowances.institute_id', Select::SQL_STAR, Select::JOIN_RIGHT);


// create a new result set based on the Album entity
            $resultSetPrototype = new ResultSet();
            $resultSetPrototype->setArrayObjectPrototype(new AllowanceApproval());
            // create a new pagination adapter object
            $paginatorAdapter = new DbSelect(
                    // our configured select object
                    $select,
                    // the adapter to run it against
                    $this->tableGateway->getAdapter(),
                    // the result set to hydrate
                    $resultSetPrototype
            );
            $paginator = new Paginator($paginatorAdapter);
            return $paginator;
        }

        $select = new Select('approval_for_allowances');
        $select->columns(array('*'));
        $select->join('institutes', 'institutes.id=approval_for_allowances.institute_id', Select::SQL_STAR, Select::JOIN_RIGHT);

        $resultSet = $this->tableGateway->selectWith($select);
        return $resultSet;
    }

我有这个功能 if语句之外的代码正常工作,内部代码没有。给我这个消息:

无法执行声明(42S21 - 1060 - 重复列名称' id')

1 个答案:

答案 0 :(得分:0)

我找到了答案......

       if ($paginated) {
            // create a new Select object for the table album
            $select = new Select('approval_for_allowances');
            $select->columns(array('*'));
            $select->join('institutes', 'institutes.id=approval_for_allowances.institute_id', array('*'), 'left');

// create a new result set based on the Album entity
            // create a new pagination adapter object
            $paginatorAdapter = new DbSelect(
                    // our configured select object
                    $select,
                    // the adapter to run it against
                    $this->tableGateway->getAdapter()
            );
            $paginator = new Paginator($paginatorAdapter);
            return $paginator;
        }