D
D
Dmitry Kim2017-05-02 11:12:12
Yii
Dmitry Kim, 2017-05-02 11:12:12

How to document parent in IDE using YII2 example?

There is a trait:

<?php

    namespace X\Y\Z;

    use yii\db\ActiveRecord;

    /**
     * Class SaveRelationTrait
     * @package X\Y\Z;
     */
    trait SaveRelationTrait
    {
        /**
         * @param      $data
         * @param null $formName
         * @return bool
         */
        public function load($data, $formName = null)
        {
            /* @var $this ActiveRecord|SaveRelationBehavior */
            // v==== вот в этом месте IDE не понимает, кто такой parent, хотя мы как бы указали, что $this - это актив рекорд. ЧЯДНТ?
            if (parent::load($data, $formName)) {
                $this->loadRelations($data, $this->formName());

                return true;
            }

            return false;
        }
    }

b0de14c84ecd4f2ea30f66dbf5b78337.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ilya Karavaev, 2017-05-02
@kimono

I don't think so.
The trait must implement common functions. And it can be injected into any class. What makes you think that the class that implements the trait will inherit from the class you need and have the corresponding function?
The only advice is to use the same $this.
Or use not a trait, but an intermediate model, since you clearly mean the use of this function only in the model and only in ActiveRecord

M
Maxim Timofeev, 2017-05-02
@webinar

I would do it through behavior and not through trait, which will solve a lot of problems, but will be slightly slower.
I advise you to read this article:
Behavior or trait

M
mitaichik, 2017-05-02
@mitaichik

Try the mixin annotation
https://youtrack.jetbrains.com/issue/WI-1730

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question