Yii2 traits library which used in web-application development.
Trait add perform ajax validation to models and forms.
use demmonico\models\Model as parent or set in you model
use AjaxValidationTrait;
in controller
if (!is_null($validate = $model->performAjaxValidation()))
return $validate;
!!! This trait is DEPRECATED Use demmonico/reflection instead!!!
Trait generates array of class constant labels or one label by constant value
set in your model
use ConstantTrait;
const NAME_FIRST = 1;
const NAME_SECOND = 2;
then anywhere get array values and names of constants:
ModelName::getName(); // returns array(1 => 'First', 2 => 'Second');
or
$model->getName(); // returns array(1 => 'First', 2 => 'Second');
Whether get name by constant value:
ModelName::getName(ModelName::NAME_FIRST); // returns 'First';
Comments