How to put yiibooster textField inside /view/layout/main.php in Yii

I am using YiiBooster and trying to make a TextField inside TbActiveForm inside /views/layouts/main.php

For the controller, I added:

<?php
    class LayoutsController extends Controller
    {
        public function actionMain()
        {
                    $model=new Item;
                    $this->render('main',array('model'=>$model));
        }
    }
?>

And views:

<?php 
 $this->beginWidget(
     'booster.widgets.TbActiveForm',
           array(
               'id' => 'inlineForm',
               'type' => 'inline',
                'htmlOptions' => array('class' => 'well'),
           )
      );
 echo $form->textFieldGroup($model, 'textField');
 $this->endWidget();
?>

But I have a small problem, when I try to start, I get an error message:

PHP notice
Undefined variable: model

Can someone help me fix this? Thank.

+4
source share
1 answer

Point: 1

If you use only the $ this-> widget, then form input elements (e.g. textFields, textAreas, dropdownlists, checkBoxes, etc.) will be placed outside the form. as

<form method="post" action="#">

</form>
<!-- and then the input elements of form, like -->
<input type="text" name="textField"> <!-- and so on.... -->

Point: 2

,

$this->beginWidget
// then the input elements , and finally
$this->endWidget();

, HTML

<form method="post" action="#">
    <input type="text" name="textField"> <!-- and so on.... -->
</form>

: 3

beginWidget ($ form)

(i)

public function actionFunctionName()
{
     $model=new ModelClassName;
     $this->render('viewFileName',array('model'=>$model));
}

(ii)

<?php
$form=$this->beginWidget(
    'booster.widgets.TbActiveForm',
    array(
        'id' => 'inlineForm',
        'type' => 'inline',
        'htmlOptions' => array('class' => 'well'),
    )
);
echo $form->textFieldGroup($model, 'textField');
// before the close tag of php
$this->endWidget();
?>

.

: 4

, YiiBooster. , .:)

+2

Source: https://habr.com/ru/post/1548232/


All Articles