0

我尝试使用自定义字段创建另一个自定义字段,但出现错误。我创建了该示例代码以便于理解。

模型.php:

public custom1;
public custom2;

示例代码:

...
$criteria->select=array("'custom1' AS custom1, CONCAT('variable: ', custom1) AS custom2");
...

错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'custom1' in 'field list'. 
4

1 回答 1

2

好吧,因为你在 select 中使用了函数,所以它必须与 CDbExpression 一起使用:

$criteria->select = array(
  new CDbExpression('custom as custom1'),
  new CDbExpression('CONCAT("variable: ", custom) AS custom2'),
);
于 2013-01-09T06:39:19.020 回答