Answer the question
In order to leave comments, you need to log in
[[+content_image]]
Why doesn't validator work in yii2?
There is a model method rules()
public function rules()
{
....
[['url'], '\backend\components\BannerValidator'],
....
}
namespace backend\components;
use Yii;
use yii\validators\Validator;
class BannerValidator extends Validator
{
/**
* @inheritdoc
*/
public function validateAttribute($object, $attribute)
{
$this->addError($object, $attribute, 'errrerer');
}
}
<?= $form->field($model, 'url')->textInput(['maxlength' => 255]) ?>
Answer the question
In order to leave comments, you need to log in
You also need to describe the clientValidateAttribute method, as an example you can look here =>
https://github.com/yiisoft/yii2/blob/master/framew...
OR
The problem is in the controller, here is a working example =>
public function actionCreate()
{
$model = new Menu();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question