I am new to Yii2 Framework and I need to understand the users status. I need to create an app that assign many statuses to the user, comparing to just 2 that Yii2 gave. In Yii2 common\models\Users
there are two constants: STATUS_DELETED = 0;
and STATUS_ACTIVE = 10;
. There is a block of code that limits the range of the value of status to 0-10, which is STATUS_DELETED
and STATUS_ACTIVE
. If I need to add other status like STATUS_DISABLED = 20
in the rules()
part, how do I modify this block? Do I need to remove the STATUS_ACTIVE
and replace it with STATUS_DISABLED
, or I should just limit the value of STATUS_DISABLED
to be within the range of 0-10. How do I make this work? I don't understand this part.
class User extends ActiveRecord implements IdentityInterface
{
const STATUS_DELETED = 0;
const STATUS_ACTIVE = 10;
const STATUS_DISABLED = 20; // I want to add this
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%user}}';
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
TimestampBehavior::className(),
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
['status', 'default', 'value' => self::STATUS_ACTIVE],
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
];
}
}