O'Reilly logo

Yii2 By Example by Fabrizio Caldarelli

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using ActiveForm

Now we will create an HTML form in view to send data from view to controller. We could build a form in the standard way using the form tag and input fields, but Yii2 provides helper classes that simplify the building of a form and its content.

For this purpose, we will use ActiveForm, a widget that builds an interactive HTML form for one or multiple data models.

As for any Yii2 widget, we will indicate with the begin()static method, the moment we start using it, and with the end()static method, the moment we stop using it, from yii\widgets\ActiveForm. The code between these methods will be placed in the form:

$form = ActiveForm::begin();
... content here ...
ActiveForm::end();

The first method, begin(), returns an object that we can ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required