S
S
seddi2016-02-06 12:35:19
Yii
seddi, 2016-02-06 12:35:19

Add YII2 status?

How to add a couple more statuses?
We have

const STATUS_ACTIVE = 10;
    const STATUS_USER = 15;

and if I add in the User model
const STATUS_DELETED = 0;
    const STATUS_ACTIVE = 10;
    const STATUS_WAIT = 2;
    const STATUS_USER = 15;
and in
public function rules()
    {
        return [
            ['status', 'default', 'value' => self::STATUS_ACTIVE],
            ['status', 'in', 'range' => [
                self::STATUS_ACTIVE,
                self::STATUS_DELETED,
                self::STATUS_WAIT,
                self::STATUS_USER
            ]],
        ];
    }

it doesn't let

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nikita, 2016-02-06
@seddi

Look towards the findIdentity() method, if I understand your picture correctly, then the whole point is hidden there)

M
Maxim Timofeev, 2016-02-06
@webinar

rules is form validation. It allows or forbids saving a user with this status. And access rulitsya in the controller.

S
seddi, 2016-02-07
@seddi

found, it was necessary to add these statuses in the findIdentity and findByUsername functions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question