M
M
michaelromanov902016-10-18 03:17:04
Yii
michaelromanov90, 2016-10-18 03:17:04

How to avoid warning on beforeValidate() in Yii2?

Good afternoon.
I want to get rid of the warning (and understand what's wrong), but I don't understand why it occurs.
In a model that inherits from active record, I have a method

public function beforeValidate() {
        //shopinf
        if(!empty( $shopinf = Yii::$app->Union->getProfile([
            'user'=>Yii::$app->User->getUser()
        ]) )){
            $this->shopinf = $shopinf['id'];
        }
        return parent::beforeValidate();
    }

And I do
80a0269cb34b41939a141aa333c51605.JPG
n’t understand why php tells me about yii\base\Model
, such options don’t help either
public function beforeValidate($data) {
        //shopinf
        if(!empty( $shopinf = Yii::$app->Union->getProfile([
            'user'=>Yii::$app->User->getUser()
        ]) )){
            $this->shopinf = $shopinf['id'];
        }
       return parent::beforeValidate($data);
    }

and (also doesn't help)
public function beforeValidate() {
        //shopinf
        if(!empty( $shopinf = Yii::$app->Union->getProfile([
            'user'=>Yii::$app->User->getUser()
        ]) )){
            $this->shopinf = $shopinf['id'];
        }
       //return parent::beforeValidate();
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Tereshchenko, 2016-10-18
@michaelromanov90

public function beforeValidate() {
        //shopinf
    if (!empty( $shopinf = Yii::$app->Union->getProfile(['user'=>Yii::$app->User->getUser()]))) {
        $this->shopinf = $shopinf['id'];
    }
    if (parent::beforeValidate()) {
       return true;
    }
    return false;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question