PHP code example of sonkei / yii2-status

1. Go to this page and download the library: Download sonkei/yii2-status library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sonkei / yii2-status example snippets


'modules' => [
    // ...
    'status' => [
        'class' => 'sonkei\status\Module'
    ]
    // ...
]

// ...
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
        ],
        // ...
    ];
}
// ...

$user->addStatus(Status::getByStatusLabel('Заблокирован'))