Join 如何在zendframework 2中向tablegateway添加联接列

Join 如何在zendframework 2中向tablegateway添加联接列,join,zend-framework2,zend-db,Join,Zend Framework2,Zend Db,我现在正在与Zend进行斗争,以使sql字符串中的联接表列正确 我有以下代码(工作正常): 但我无法让acl_groups列正常工作。 任何尝试都失败了。我已经阅读了Zend文档,但没有任何东西对我有效 我的联接表包含以下列: id name status 我需要一个别名“groupname” 我试过这个: $select->columns(array( $select::SQL_STAR, 'group', 'id', 'status', arr

我现在正在与Zend进行斗争,以使sql字符串中的联接表列正确

我有以下代码(工作正常):

但我无法让acl_groups列正常工作。 任何尝试都失败了。我已经阅读了Zend文档,但没有任何东西对我有效

我的联接表包含以下列:

id
name
status
我需要一个别名“groupname”

我试过这个:

$select->columns(array(
    $select::SQL_STAR,
    'group',
    'id',
    'status',
    array('acl_groups.name' => 'groupname')
)

$select->columns(array(
    $select::SQL_STAR,
    'group',
    'id',
    'status',
    'acl_groups.name AS groupname'
)

但是没有一种是有效的。

如前所述,有两种方法可以做到这一点

方法1

 $resultSet = $tableGateway->select (function (Select $select) {
    // now you have `select` object, do whatever you like
});
方法2

$select = new Select('table_name');
$select->join(
  'another_table_name',
  'join condition',
  array('column of another table name'),
  Select::JOIN_INNER
);
$resultSet = $tableGateway->selectWith($select);

事实上,这种用法有点奇怪:array('joinfield'=>'aliasname'),我们应该注意array('aliasname'=>'joinfield')。根据经验,我认为这太可怕了!!!
$select = new Select('table_name');
$select->join(
  'another_table_name',
  'join condition',
  array('column of another table name'),
  Select::JOIN_INNER
);
$resultSet = $tableGateway->selectWith($select);