我正在使用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配置.
我希望它对你有所帮助.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。