Answer the question
In order to leave comments, you need to log in
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;
}
}
Answer the question
In order to leave comments, you need to log in
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
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question