在我的模型TblTrucks中我添加了
class TblTrucks extends \yii\db\ActiveRecord
{
public $rejected_reason;
public function rules()
{
return [
[['rejected_reason'], 'safe'],
]
}
}
每当我尝试设置值
时,现在在我的控制器中$trucks = TblTrucks::find()->all();
foreach($trucks as $key=>$value){
$value->rejected_reason = "test here";
}
return $trucks;
我收到错误
TblTrucks没有名为“rejected_reason”的属性。
我哪里可能出错?
我也尝试在我的模型中添加一个字段数组,如
public function fields()
{
$fields = parent::fields();
$fields['rejected_reason'] =function ($model){
return $this->rejected_reason;
};
return $fields;
}
答案 0 :(得分:0)
只需更改您的查询,如下所示:
$trucks = TblTrucks::find()
->select('your_table_name.*,"test here" as rejected_reason') // replace with your table name
->all();