Yii2 render two models in one view

情到浓时终转凉″ 提交于 2019-12-12 03:18:31

问题


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));
            ?>

回答1:


try this way

In your Controller

$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



来源:https://stackoverflow.com/questions/34144553/yii2-render-two-models-in-one-view

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!