E
E
Evgeny Milushkin2015-08-01 09:55:44
Yii
Evgeny Milushkin, 2015-08-01 09:55:44

Yii2: Why can't I get the computed property of an ActiveRecord model?

Hello.
Communication announced:

/** @var app\models\Goods $this*/
public function getProducer()
    {
        return $this->hasOne(GoodProducers::className(), ['id' => 'fk_producers']);
    }

In View I use the following code to display the full name of the product:
/** @var app\models\Goods $model */
<?= $model->producer->name . ' ' . $model->name; ?>

The name of the product along with the manufacturer are displayed normally.
If I try to declare a new property of the Goods $fullName model, then the name of the manufacturer is not displayed.
/** @var app\models\Goods $this*/
public $fullName;
public function getFullName()
{
     return $this->producer->name . ' ' . $this->name;
}

Why here when debugging $this->producer->name PhpStorm writes
that "Cannot evaluate expression" , although there is a producer in $this->$_related?
The documentation describes that it is possible to convert data
https://github.com/yiisoft/yii2/blob/master/docs/g...
Why doesn't it work with related data?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question