Yii2 statuses module. Good when object have a lot of statuses, like is_active
, banned
, indexed
, moderated
, etc.
sonkei/yii2-status
is designed to work out of the box. It means that installation requires minimal steps. Only one configuration step should be taken and you are ready to use this module on your Yii2 website.
sonkei/yii2-status
can be installed using composer. Run following command to download and install sonkei/yii2-status
:
composer require sonkei/yii2-status
In you project configuration register sonkei/yii2-status
module
'modules' => [
// ...
'status' => [
'class' => 'sonkei\status\Module'
]
// ...
]
Copy migrations that could be found in vendor/sonkei/yii2-status/dist/migrations
and run yii2 migration tool.
Or you can apply migration straight from vendor
yii migrate/up --migrationPath=@vendor/sonkei/yii2-status/dist/migrations
// ...
function getStatuses()
{
return $this->hasMany(Status::className(), ['id' => 'status_id'])
->viaTable(ObjectStatus::tableName(), ['object_id' => 'id']);
}
// ...
// ...
function behaviors() {
return [
// ...
[
'class' => 'sonkei\status\behaviors\StatusableBehavior',
'status_relation' => 'statuses' // The relation connecting statuses and your object
],
// ...
];
}
// ...
Configure available statuses within the module (http://mysupercoolsite.com/status)
$user->addStatus(Status::getByStatusLabel('Заблокирован'))