php - Yii 选择使用自定义字段

标签 php mysql yii

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

模型.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'. 

最佳答案

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

$criteria->select = array(
  new CDbExpression('custom as custom1'),
  new CDbExpression('CONCAT("variable: ", custom) AS custom2'),
);

关于php - Yii 选择使用自定义字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14205195/

相关文章:

php - 使用 PHP 返回 reddit 中的链接列表

php - 是否可以在此代码中创建重复的 ip?

PHP 表单提交时 SQL 查询结果在空白表中?

css - 如何在 yii 中使用 scriptMap 加载 css 文件?

php - 消息 : SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

php - 错误: Call to a member function paginate() on a non-object

mysql - 数据库架构 : how to make dynamic table according to type?

phpmailer 抛出 mysql 错误

php - 如果日期相等,Array_multisort 将失败

php - 根据对方法的外部或内部调用选择性地公开函数