4

私は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();
?>

しかし、実行しようとするとエラーメッセージが表示されるという小さな問題があります。

PHP notice
Undefined variable: model

誰でもこれを修正するのを手伝ってもらえますか? ありがとう。

4

1 に答える 1

2

ポイント: 1

$this->widgetのみを使用すると、フォームの入力要素(例: 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の設定を確認してください。お役に立てば幸いです。:)

于 2014-07-13T07:52:34.860 に答える