Hello, please I need help, 'cause don’t know where I’m wrong.
In an yii2 app I have two tables:
CREATE TABLE IF NOT EXISTS `umarker` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID Segnalazione',
`status_id` int(10) unsigned NOT NULL COMMENT 'Stato segnalazione',
PRIMARY KEY (`id`),
KEY `status_id` (`status_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
ADD CONSTRAINT `umarker_ibfk_2` FOREIGN KEY (`status_id`) REFERENCES `umarkerstat` (`id`),
CREATE TABLE IF NOT EXISTS `umarkerstat` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`status` varchar(60) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
In Umarker.php there is relational data field
public function getStatus()
{
return $this->hasOne(Umarkerstat::className(), ['id' => 'status_id']);
}
Then, in view there are
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'status_id',
],
]) ?>
Of course I will prefer to show text field instead of id. So I tried:
'attributes' => [
'id',
'umarkerstat.status_id',
],
and
'attributes' => [
'id',
[
'label' => 'Status',
'value' => $model->umarkerstat->status_id,
],
],
In both cases, obtaining:
Unknown Property – yii\base\UnknownPropertyException
Getting unknown property: app\models\Umarker::umarkerstat
where am I wrong, please?