sonkei / yii2-status
Status module for Yii2
Installs: 32
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 2
Open Issues: 0
Type:yii2-extension
This package is not auto-updated.
Last update: 2021-11-03 05:41:07 UTC
README
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.
Installation:
1. Download
sonkei/yii2-status
can be installed using composer. Run following command to download and install sonkei/yii2-status
:
composer require sonkei/yii2-status
2. Configure
1. Register module
In you project configuration register sonkei/yii2-status
module
'modules' => [ // ... 'status' => [ 'class' => 'sonkei\status\Module' ] // ... ]
2. Apply migration
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
3. Add relation to status linking table (object_status) to your model
// ... function getStatuses() { return $this->hasMany(Status::className(), ['id' => 'status_id']) ->viaTable(ObjectStatus::tableName(), ['object_id' => 'id']); } // ...
4. Add behavior to your model
// ... function behaviors() { return [ // ... [ 'class' => 'sonkei\status\behaviors\StatusableBehavior', 'status_relation' => 'statuses' // The relation connecting statuses and your object ], // ... ]; } // ...
5. Configure statuses
Configure available statuses within the module (http://mysupercoolsite.com/status)
6. Use it
$user->addStatus(Status::getByStatusLabel('Заблокирован'))