Paginator和Select with join

时间:2014-03-17 16:54:37

标签: select zend-framework pagination zend-framework2 zend-paginator

在我目前的ZF2项目中,我使用了Paginator,但我遇到了一个问题。

当我使用带有选择连接的Paginator时,我无法显示不属于我的Servicegroup对象的对象元素。

# Create a new Select object
      $Select = new Select();
      $Select->from('t_service_group')
             ->join('t_user_group', 't_user_group.user_group_id = t_service_group.fk_user_group_id')
             ->order('service_group_name ASC');

      # Create a new result set
      $resultSetPrototype = new ResultSet();
      $resultSetPrototype->setArrayObjectPrototype(new ServiceGroup());

      # 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;

你知道如何使用paginator而不使用:

 setArrayObjectPrototype(new ServiceGroup());

谢谢大家的帮助 最好的问候

修改

如果在查询分页器中使用带连接的选择查询。你必须这样做:

     # Create a new Select object
      $Select = new Select();
      $Select->from('t_service_group')
             ->join('t_user_group', 't_user_group.user_group_id = t_service_group.fk_user_group_id')
             ->order('service_group_name ASC');

      # Create a new result set
      $resultSetPrototype = new ResultSet();
#      $resultSetPrototype->setArrayObjectPrototype(new ServiceGroup());

      # 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;

1 个答案:

答案 0 :(得分:0)

你很简单,不要设置resultsetprototype,并使用默认的结果集原型,它将填充从行返回的所有值