简体   繁体   中英

How Can I Set Global Validation Rule - YII2

I have started with YII2 just today. i have installed it successfully and also created required Model, Controllers & views in that using CRUD.

Now my question is as below:

I want to create one Global Validator Rule which we can use in throughout the Models in system.

What i have tried so far:

For that i have created one new model file(FormValidator) in common folder and generate one custom rule method in it.

common/model/FormValidator.php

namespace common\models;

use Yii;
use yii\base\Model;

class FormValidator extends \yii\db\ActiveRecord {

}

then i tried to extend this model file to my frontend model file. but its not working.

frontend/model/Customerprofile.php

namespace frontend\models;

use Yii;
use common\models\FormValidator;    

class Customerprofile extends FormValidator{

}

It's throw below error message:

PHP Fatal Error – yii\base\ErrorException

Class 'common\models\FormValidator' not found

I don't know what i have missing in all these process, if anyone of you help me out from this, would be much appreciated!

Thanks in Advance.

如果要为模型扩展某个主类,则只需扩展CActiveRecord,然后您的模型将扩展此主类。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM