dev-master
9999999-dev https://github.com/urmaul/enumattributesYii ActiveRecord behavior used to work with ENUM attributes.
MIT
The Requires
yii behavior enum
Wallogit.com
2017 © Pedro Peláez
Yii ActiveRecord behavior used to work with ENUM attributes.
Yii ActiveRecord behavior used to work with ENUM attributes, (*1)
composer require urmaul/yii-enumattributes dev-master
You need to add this behavior to behaviors:, (*2)
public function behaviors()
{
return array(
...
'statusEnum' => array(
'class' => 'EnumAttributesBehavior',
'attribute' => 'status',
),
);
}
And also you should add behavior property to phpDoc comments:, (*3)
/** * ... * * @property EnumAttributesBehavior $statusEnum */ class ...
Now you can retrieve list of possible values by calling behavior like that:, (*4)
$model->statusEnum->values
Values order is equal to values order in DB structure., (*5)
Or you can retrieve a map "value => label" by calling behavior like that:, (*6)
$model->statusEnum->valueLabels
Values order is equal to values order in DB structure., (*7)
Labels are generated from values using CModel::generateAttributeLabel function. You can set custom labels using the labels behavior option., (*8)
This behavior can generate validation rule for you., (*9)
public function rules()
{
return array(
...
$this->statusEnum->rule,
// or
$this->statusEnum->rule + array('on' => 'create'),
...
);
}
Yii ActiveRecord behavior used to work with ENUM attributes.
MIT
yii behavior enum