编程语言
首页 > 编程语言> > 如何将yiibooster的textField放在Yii中的/view/layout/main.php中

如何将yiibooster的textField放在Yii中的/view/layout/main.php中

作者:互联网

我正在使用YiiBooster并尝试在/views/layouts/main.php中的TbActiveForm中创建一个TextField

对于我添加的控制器:

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

意见:

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

但我有小问题,当试图运行它时出现错误信息:

06002

任何人都可以帮我解决这个问题吗?谢谢.

解决方法:

要点:1

如果您只使用$this->小部件,则表单的输入元素(例如,textFields,textAreas,dropdownlists,checkBoxes等)将放在表单的旁边.喜欢

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

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

要点: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配置.
我希望它对你有所帮助.

标签:php,yii,yii-extensions,yii-booster
来源: https://codeday.me/bug/20190703/1363934.html