【问题标题】:Error InputWidget.php line 75 properties must be specified错误 InputWidget.php 必须指定第 75 行属性
【发布时间】:2018-04-10 23:01:06
【问题描述】:

我想使用Input Tags Widget 制作带有标签的输入字段。但是我收到了这个错误:

“名称”或“模型”和“属性”属性必须是 指定。

在 /var/www/html/paramoor/vendor/yiisoft/yii2/widgets/InputWidget.php 第 75 行:

/**
 * Initializes the widget.
 * If you override this method, make sure you call the parent implementation first.
 */
public function init()
{
    if ($this->name === null && !$this->hasModel()) {
        throw new InvalidConfigException("Either 'name', or 'model' and 'attribute' properties must be specified.");
    }
    if (!isset($this->options['id'])) {
        $this->options['id'] = $this->hasModel() ? Html::getInputId($this->model, $this->attribute) : $this->getId();
    }
    parent::init();
}

这是我的查看代码:

<?= $form->field($modelDetail, 'product_id')->widget(TagsinputWidget::classname(),
[
    'clientOptions' => [
        'trimValue' => true,
        'allowDuplicates' => false,
        'delimiter' => ';',
    ],
]) ?>

【问题讨论】:

  • 什么是$modelDetail?它是Model 派生类型吗?你确定product_id 吗?这个属性包含标签?不常见的名字...

标签: yii2 tags yii2-extension


【解决方案1】:

在为字段/过滤器/等使用小部件时,您需要提供其中一个(或两个)选项。你有两个选择:

给出模型和属性:

<?= $form->field($modelDetail, 'product_id')->widget(TagsinputWidget::classname(),
[
    'model' => $modelDetail,
    'attribute' => 'product_id',
    'clientOptions' => [
        'trimValue' => true,
        'allowDuplicates' => false,
        'delimiter' => ';',
    ],
]) ?>

只给出名称(作为模型和属性名称的组合):

<?= $form->field($modelDetail, 'product_id')->widget(TagsinputWidget::classname(),
[
    'name' => 'ModelDetail[product_id]',
    'clientOptions' => [
        'trimValue' => true,
        'allowDuplicates' => false,
        'delimiter' => ';',
    ],
]) ?>

我建议使用第一个选项,就像更改模型名称一样,您无需搜索此模型名称用作字符串的位置。

【讨论】:

  • 我试过像你上面那样添加模型或属性或名称,但它不起作用。它仍然得到Either 'name', or 'model' and 'attribute' properties must be specified. 错误
猜你喜欢
  • 2012-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-23
  • 1970-01-01
  • 2014-12-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多