Answer the question
In order to leave comments, you need to log in
Why is related tables not showing in DetailView?
I have related tables
public function getIdSotrud()
{
return $this->hasOne(User::className(), ['id' => 'id_sotrud']);
}
public function actionView($id)
{
$user->idSotrud->name;
return $this->render('view', [
'model' => $this->findModel($id),
'user' => $user,
]);
}
DetailView::widget([
[
'attribute' => 'id_sotrud',
'value' => $user,
],
])
Answer the question
In order to leave comments, you need to log in
It is not displayed because you wrote nonsense. Before you write the code to the dock, you would read
public function actionView($id)
{
$user->idSotrud->name; // что за переменная $user откуда она взялась? что Вы вообще хотите сделать в этой строке.
return $this->render('view', [
'model' => $this->findModel($id),
'user' => $user,
]);
}
DetailView::widget([
[
'attribute' => 'id_sotrud', // а тут что Вы ожидаете увидеть?
// данные реляции? так Вы ж их не выводите
'value' => $user,
],
])
You would include errors, as it $user->idSotrud->name;
would immediately give an error.
public function actionView($id)
{
$user->idSotrud->name; // тут же у Вас просто переменная из ниоткуда появилась
return $this->render('view', [
'model' => $this->findModel($id), //тут тоже
'user' => $user,
]);
}
public function actionView($id)
{
$model = MyModel::find()->andWhere(['id'=>$id])->with('idSotrud')->one();
$sotrud_name = $model->idSotrud->name;
return $this->render('view', [
'model' => $model,
'sotrud_name' => $sotrud_name,
]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question