Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Zend\Paginator\Paginator's getItem() trigger an "Fatal error: ..." #6812

Closed
tasmaniski opened this issue Oct 27, 2014 · 8 comments
Closed

Zend\Paginator\Paginator's getItem() trigger an "Fatal error: ..." #6812

tasmaniski opened this issue Oct 27, 2014 · 8 comments
Assignees
Milestone

Comments

@tasmaniski
Copy link

Fatal error: Cannot use object of type Zend\Db\ResultSet\ResultSet as array

I got this error in Zend\Paginator\Paginator when I call method getItem()

Eg:

$select = $myMapper->getSqlSelect();
$resultSet = new ResultSet();
$paginatorAdapter = new DbSelect($select, $myMapper->getAdapter(), $resultSet);
$paginator = new Paginator($paginatorAdapter);

//echo get_class($paginator); Zend\Paginator\Paginator
$paginator->getItem(1);

@tasmaniski tasmaniski changed the title Zend Paginatinator trigger fatal error when call getItem() Zend\Paginator\Paginator's getItem() trigger an "Fatal error: Cannot use object of type Zend\Db\ResultSet\ResultSet as array" Oct 27, 2014
@tasmaniski tasmaniski changed the title Zend\Paginator\Paginator's getItem() trigger an "Fatal error: Cannot use object of type Zend\Db\ResultSet\ResultSet as array" Zend\Paginator\Paginator's getItem() trigger an "Fatal error: ..." Oct 27, 2014
@samsonasik
Copy link
Contributor

could you try remove , $resultSet from the DbSelect parameter list, i'm not test it, but it should be ok with :

 $paginatorAdapter = new DbSelect($select, $myMapper->getAdapter());

@tasmaniski
Copy link
Author

Still same...
I guess it's a bug, but I am waiting for someone else to confirm too.

@samsonasik
Copy link
Contributor

I've tested with Album module from zf2 doc and its work. i've tested with :

     public function fetchAll($paginated=false)
     {
     $sql = $this->tableGateway->getSql();

         if ($paginated) {
             $paginatorAdapter = new DbSelect(
                 $select,
                 $this->tableGateway->getAdapter()
             );

             $paginator = new Paginator($paginatorAdapter);
             return $paginator;
         }

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

could you confirm what your code as :

$select = $myMapper->getSqlSelect();

?

@tasmaniski
Copy link
Author

Thanks for replay..

I just cloned a fresh install of ZF2(skeleton app) and pass through tutorial from the web site
http://framework.zend.com/manual/2.2/en/tutorials/tutorial.pagination.html#modifying-the-albumtable

Everithing works fine, as long as you don't call the function getItem()

public function fetchAll($paginated = false)
{
    if($paginated){
        $select             = new Select('album'); //Zend\Db\Sql\Select
        $resultSetPrototype = new ResultSet(); //Zend\Db\ResultSet\ResultSet
        $resultSetPrototype->setArrayObjectPrototype(new Album());
        $paginatorAdapter   = new DbSelect($select, $this->tableGateway->getAdapter(), $resultSetPrototype);
        $paginator          = new Paginator($paginatorAdapter); //Zend\Paginator\Paginator

        //$paginator->getItem(1); // Trigger fatal error

        return $paginator;
    }

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

the same situation is on my work computer as well on my home laptop
and I am using Ubuntu with Apache.

@samsonasik
Copy link
Contributor

oops, yes. I think it's actually an issue. I think on Paginator::getItem() should be changed before $page[$itemNumber - 1]:

        if (!is_array($page)) {
            $temp = array();
            foreach($page as $p) {
                $temp[] = $p;
            }
            $page = $temp;
        }

@samsonasik
Copy link
Contributor

the actual issue is on Zend\Paginator\Adapter\DbSelect::getItems that need return array instead of Zend\Db\ResultSet\ResultSet

@samsonasik
Copy link
Contributor

@tasmaniski I give a try at PR #6817 for it.

samsonasik added a commit to samsonasik/zf2 that referenced this issue Nov 22, 2014
samsonasik added a commit to samsonasik/zf2 that referenced this issue Nov 29, 2014
samsonasik added a commit to samsonasik/zf2 that referenced this issue Dec 4, 2014
Ocramius added a commit that referenced this issue Dec 5, 2014
Ocramius added a commit that referenced this issue Dec 5, 2014
Ocramius added a commit that referenced this issue Dec 5, 2014
Ocramius added a commit that referenced this issue Dec 5, 2014
@UFOMelkor
Copy link
Contributor

Fixed in #6817

@Ocramius Ocramius self-assigned this Dec 15, 2014
@Ocramius Ocramius modified the milestones: 2.3.4, 2.4.0 Dec 15, 2014
gianarb pushed a commit to zendframework/zend-paginator that referenced this issue May 15, 2015
gianarb pushed a commit to zendframework/zend-paginator that referenced this issue May 15, 2015
gianarb pushed a commit to zendframework/zend-paginator that referenced this issue May 15, 2015
gianarb pushed a commit to zendframework/zend-paginator that referenced this issue May 15, 2015
gianarb pushed a commit to zendframework/zend-paginator that referenced this issue May 15, 2015
…DbSelect#getItems()` should return `array` types
gianarb pushed a commit to zendframework/zend-paginator that referenced this issue May 15, 2015
…ixed `@group` annotations to comply with `DbSelectTest` ones
gianarb pushed a commit to zendframework/zend-paginator that referenced this issue May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants