Yii2 在一个视图中渲染两个模型 [英] Yii2 render two models in one view
本文介绍了Yii2 在一个视图中渲染两个模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Yii 是最好的,但我有两个模型, book 和 author .我需要在一个视图中为每个表单处理两个表单,就像我在 yii2.0 中所做的那样.
Yii is the best but I'm have two models , book and author . I need to process two forms for each one in a single view , as I do this in yii2.0 .
<?=
$this->render('_formBook', array('model' => $model));
?>
<?=
$this->render('_formAuthor', array('model' => $model));
?>
推荐答案
试试这个方法
在你的控制器中
$modelBook = Book::findOne($id);
$modelAuthor = Author::findOne($key);
return $this->render('_formWithTheTwoForm',
'modelBook' => $modelBook,
'modelAuthor' => $modelAuthor,]);
然后在您的视图中您可以同时使用模型
Then in your view you can use both the model
这篇关于Yii2 在一个视图中渲染两个模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文