简体   繁体   中英

Yii2 render two models in one view

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM