問題是,該方法$select->columns()
覆蓋現有的專欄。
爲了解決這個問題,您可以擴展自己的「select」並添加一個新的方法到「添加」列(因爲Select類的列屬性受保護)。
示例;
CustomSelect.php
class CustomSelect extends \Zend\Db\Sql\Select
{
/**
* @param array $columns
* @param bool $prefixColumnsWithTable
* @return $this
*/
public function addColumns(array $columns, $prefixColumnsWithTable = true) {
$this->columns = $this->columns + $columns;
$this->prefixColumnsWithTable = (bool) $prefixColumnsWithTable;
return $this;
}
}
用法:
$select = new CustomSelect();
$select->addColumns(['type' => new \Zend\Db\Sql\Expression("'foo'")]);
$select->addColumns(['*']); //This is the default value though - so adding after adding shouldn't be nessecary (except if you've used "columns()" before)
這工作。謝謝! – Matt