[英]How to call another DetailView::widget from another model in one view YII2?
我是yii2
。 我在DetailView::widget
有一個表的顯示數據。
我想為另一個表調用另一個DetailView::widget
,然后在同一視圖中顯示。
您可以在同一視圖中使用兩個DetailView
小部件,這沒有問題。
在控制器中:
use yii\web\NotFoundHttpException;
...
public function actionView($id)
{
$model1 = $this->findModel($id);
$model2 = ModelName::find()->where(['id' => ...])->one();
if (!$model2) {
throw new NotFoundHttpException('Second model not found');
}
return $this->render('view', [
'model1' => $model1,
'model2' => $model2,
]);
}
鑒於:
<div class="col-md-6">
<?= DetailView::widget([
'model' => $model1,
'attributes' => [
'name',
],
]) ?>
</div>
<div class="col-md-6">
<?= DetailView::widget([
'model' => $model2,
'attributes' => [
'name',
],
]) ?>
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.