Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.
/ yii2-status Public archive
forked from itzen/yii2-status

Yii2 statuses module. Good when object have a lot of statuses, like is_active, banned, indexed, moderated, etc.

License

Notifications You must be signed in to change notification settings

anuri73/yii2-status

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sonkei/yii2-status

Yii2 statuses module. Good when object have a lot of statuses, like is_active, banned, indexed, moderated, etc.

Software License Creative Commons License

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('Заблокирован'))

About

Yii2 statuses module. Good when object have a lot of statuses, like is_active, banned, indexed, moderated, etc.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published