【问题标题】:add column to select object zend framework添加列以选择对象 zend 框架
【发布时间】:2017-10-20 19:19:42
【问题描述】:

这是我当前的代码:

$Select=new Select();
$Select->from($this->getTable());

我现在想要的是添加id column,但添加为DT_RowId 而不是id。我该如何做到这一点?目标是拥有所有表格列以及这个新列。

【问题讨论】:

  • 你能编辑你的帖子并添加你的表格定义的其余部分吗?最好是您当前的情况之一和期望的情况之一。

标签: zend-framework zend-framework2 zend-db zend-framework3 zend-db-select


【解决方案1】:

如果您同时需要“旧”和“新”字段,请不要忘记添加星号。

$Select=new \Zend\Db\Sql\Select();
$Select->from($this->getTable());
$Select->columns([
  '*', 
  'DT_RowId' => 'id',
  'furtherColumn' => 'furtherColumn'
]);

【讨论】:

    【解决方案2】:

    最简单的解决方案是使用带有关联数组的列函数,其中别名作为键,例如:

    $select=new Select();
    $select->from($this->getTable());
    $select->columns(array(
     'DT_RowId' => 'id',
     'furtherColumn' => 'furtherColumn',
    ));
    

    【讨论】:

      猜你喜欢
      • 2010-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多