I
I
in30002016-09-04 11:08:08
Yii
in3000, 2016-09-04 11:08:08

How to put the output of ActiveForm:begin()/end() functions into a variable in Yii2?

I have the following task. I have a widget that should cycle through forms for editing individual rows in the database. Naturally, if I try to add ActiveForm::begin() inside my widget, then the beginning of the form is highlighted at the very beginning of the document before the information in the header. How do I put all my ActiveForms into a variable so that I can display them in the view after that? Or in what other way can I solve my problem without moving the functionality of my widget to the view.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2016-09-04
@mhthnz

Render the form in a loop:

<?php
    foreach ($items as $num => $item) {
    	echo $this->render('_form', ['model' => $item]);
    } ?>

Or you can render in the field cycle, depending on the situation. There are fields identical that it is possible to apply multiforms.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question