答案是在模型里面覆盖 formName 方法
// file: api\models\Order.php
class Order extends \yii\db\ActiveRecord
{
public function formName()
{
return '';
}
}
具体原因是,
$model->imageFile = UploadedFile::getInstance($model, 'imageFile');
# 获取UploadFile实例的时候,如果formName不是空字符串,会导致获取不到实例
public static function getInstance($model, $attribute)
{
$name = Html::getInputName($model, $attribute);
return static::getInstanceByName($name);
}