我正在尝试在模型中使用自定义函数实现它不起作用我没有得到我的代码有什么问题。我想稍后打电话给基本的我会提出我的条件。
这是型号代码
public function rules()
{
return [
['mobile_number', 'required'],
['mobile_number', 'myfunction'],
];
}
public function myfunction($attribute,$params)
{
$this->addError($attribute, 'You have already submitted');
}
这是控制器代码
public function actionCreate()
{
$model = new Createuser();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
它没有将错误分配给表单字段。
Thanks in advance.