0

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

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

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

你知道我如何在不使用分页器的情况下使用:

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

1 回答 1

0

您简单地不设置结果集原型,而是使用默认的结果集原型,它将填充从行返回的所有值

于 2014-03-19T07:01:31.673 回答