2018-06-08 07:46
浏览 38


I would like to implement a solution where the field types of a form are coming from database. My form is an ActiveForm with a model.

I was adding the following to db:

formfield: textInput

and this to the form:

<?= $form->field($model, 'rgw')->{$model->rrgw->formfield}(['maxlength' => true]) ?>

this is the only way it works, and only for textinput. As soon as I delete (['maxlength' => true]) it's not working anymore and I get the error:

Getting unknown property: yii\bootstrap\ActiveField::textInput

Furthermore, if I want a checkbox or something else, (['maxlength' => true]) is not wanted, right? So I was trying to add () to the db, so like this:

formfield: textInput()

I'm still getting error:

Getting unknown property: yii\bootstrap\ActiveField::textInput()

How can I get rid of () part in yii and move this to the db? Can you please point me to the right direction? Many thanks for your help!

图片转代码服务由CSDN问答提供 功能建议

我想实现一个解决方案,其中表单的字段类型来自数据库。 我的表单是一个 带模型的ActiveForm。


formfield:textInput < / blockquote>


 &lt;?= $ form-&gt; field($ model,'rgw') - &gt  ; {$ model-&gt; rrgw-&gt; formfield}(['maxlength'=&gt; true])?&gt; 

这是唯一的方法 有效,仅适用于textinput。 一旦我删除(['maxlength'=&gt; true])它就不再工作了,我得到错误:

获取 未知属性:yii \ bootstrap \ ActiveField :: textInput

此外,如果我想要一个复选框或其他内容,(['maxlength'=&gt; 真的])不是,对吗? 我试图将()添加到数据库中,所以这样:



获取未知数 property:yii \ bootstrap \ ActiveField :: textInput()

如何摆脱yii中的()部分并移动它 到数据库? 你能指点我正确的方向吗? 非常感谢你的帮助!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongqian8265 2018-06-08 08:02

    textInput() and checkbox() are methods, so you need to use () to indicate that you want a methods instead of property.

    <?= $form->field($model, 'rgw')->{$model->rrgw->formfield}() ?>
    打赏 评论

相关推荐 更多相似问题