jqhph / dcat-admin

🔥 基于 Laravel 的后台系统构建工具 (Laravel Admin),使用很少的代码快速构建一个功能完善的高颜值后台系统,内置丰富的后台常用组件,开箱即用,让开发者告别冗杂的HTML代码
http://www.dcatadmin.com
MIT License
3.88k stars 707 forks source link

Undefined variable: id #715

Closed 99lucky closed 3 years ago

99lucky commented 3 years ago

Description:

编辑和创建内容的时候,提示 Undefined variable: id (View: E:\phpstudy_v8\WWW\Voyager\resources\views\dcat\views\form\input.blade.php),对照1.7.1版本发现2.0.9 版本没有了text.php文件里render方法里没有了$id属性设置,按照1.7.1版本加上后,提示没有$id属性

Steps To Reproduce:

jqhph commented 3 years ago

请贴上代码,正常新增和编辑是不会报错的

99lucky commented 3 years ago

模板文件 input.blade.php `

<div for="{{ $id }}" class="{{$viewClass['label']}} control-label">
    <span>{!! $label !!}</span>
</div>

<div class="{{$viewClass['field']}}">

    @include('admin::form.error')

    <div class="input-group">

        @if ($prepend)
            <span class="input-group-prepend"><span class="input-group-text bg-white">{!! $prepend !!}</span></span>
        @endif
        <input {!! $attributes !!} />

        @if ($append)
            <span class="input-group-append">{!! $append !!}</span>
        @endif
    </div>

    @include('admin::form.help-block')

</div>

`

程序文件2.0.9 src/form/field/text.php ` public function render() { $this->initPlainInput();

    $this->defaultAttribute('type', 'text')
        ->defaultAttribute('name', $this->getElementName())
        ->defaultAttribute('value', $this->value())
        ->defaultAttribute('class', 'form-control '.$this->getElementClassString())
        ->defaultAttribute('placeholder', $this->placeholder());

    $this->addVariables([
        'prepend' => $this->prepend,
        'append'  => $this->append,
    ]);

    return parent::render();
}`

程序文件1.7.6 ` public function render() { $this->initPlainInput();

    $this->defaultAttribute('type', 'text')
        **->defaultAttribute('id', $this->id)**
        ->defaultAttribute('name', $this->getElementName())
        ->defaultAttribute('value', old($this->column, $this->value()))
        ->defaultAttribute('class', 'form-control '.$this->getElementClassString())
        ->defaultAttribute('placeholder', $this->placeholder());

    $this->addVariables([
        'prepend' => $this->prepend,
        'append'  => $this->append,
    ]);

    return parent::render();
}

` 我对应了1.7的版本发现2.0.9版本里没有了id的变量赋值

jqhph commented 3 years ago

我是让你贴业务代码,id已经废弃了,正常是不会报错的

jqhph commented 3 years ago

我明白了,你自己自定义了模板吧,更新一下

99lucky commented 3 years ago

哦,看到了,我用的模板文件版本不一致,谢谢