在yii2 documentation我发现有一种方法可以将活动记录转换为数组.
Customer::find()->asArray()->all();
Run Code Online (Sandbox Code Playgroud)
但我不能这样使用: -
Customer::findModel($id)->asArray();
Run Code Online (Sandbox Code Playgroud)
我应该怎么做?请帮忙
aro*_*hev 16
你应该添加,而不是添加asArray()到ActiveQuery实例ActiveRecord.假设您的主键列已命名id,您应该将模型查找代码更改为:
Customer::find(['id' => $id])->asArray()->one();
Run Code Online (Sandbox Code Playgroud)
Muh*_*zad 14
$model = Customer::find($id)->asArray()->one();
Run Code Online (Sandbox Code Playgroud)
$model = Customer::find($id)->select('id,name')->asArray()->one();
Run Code Online (Sandbox Code Playgroud)
$model = Customer::find($id)->select('id,name as full')->asArray()->one();
Run Code Online (Sandbox Code Playgroud)
$model = Customer::find()->where(['email'=>$email])->asArray()->one();
Run Code Online (Sandbox Code Playgroud)
$model = Customer::find($id)->asArray()->all();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29076 次 |
| 最近记录: |