zend-frameworkzend-framework2zend-dbzend-framework3zend-db-select

add column to select object zend framework


Here is my current code:

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

What I want now is to add the id column but as DT_RowId instead of id. How do I accomplish this? The goal would be to have all of the table columns as well as this new column.


Solution

  • If you need both "old" and "new" fields, don't forget to add an asterisk.

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