【问题标题】:Add fileupload field to OctoberCMS backend using $widget->addFields?使用 $widget->addFields 将文件上传字段添加到 OctoberCMS 后端?
【发布时间】:2018-08-10 00:36:46
【问题描述】:

尝试使用 OctoberCMS 后端中的插件将类型为 fileupload 和模式 image 的表单字段添加到某个页面,但出现错误。文本、下拉菜单等类型工作正常。

当我将字段名称设置为 viewBag[photo] 时,我收到错误 "Call to a member function hasRelation() on array" on line 81 of [path]/public/modules/backend/traits/FormModelWidget.php"。

当我将名称设置为 photo 时,我得到 "Call to undefined method October\Rain\Halcyon\Builder::hasRelation()" on line 786 of [path]/public/vendor/october/rain/src/Halcyon/Builder.php"。

use System\Classes\PluginBase;
use Event;

class Plugin extends PluginBase
{
    public function boot()
    {
        Event::listen('backend.form.extendFields', function($widget) {

            if (! $widget->getController() instanceof \RainLab\Pages\Controllers\Index) {
                return;
            }

            if (! $widget->model instanceof \RainLab\Pages\Classes\Page) {
                return;
            }

            switch ($widget->model->fileName) {
                case 'about.htm':
                    $widget->addFields([
                        'viewBag[photo]' => [
                            'label' => 'Photo',
                            'mode' => 'image',
                            'imageWidth' => '200',
                            'imageHeight' => '300',
                            'useCaption' => true,
                            'thumbOptions' => [
                                'mode' => 'crop',
                                'extension' => 'auto',
                            ],
                            'span' => 'auto',
                            'type' => 'fileupload',
                        ],
                    ], 'primary');
                    break;
            }

        });
    }
}

【问题讨论】:

    标签: php octobercms octobercms-plugins octobercms-backend october-form-controller


    【解决方案1】:

    目前无法通过addFields 将fileupload 类型添加到静态页面。 mediafinder 类型必须用于图片上传。

    $widget->addFields([
        'viewBag[photo]' => [
            'label' => 'Photo',
            'mode' => 'image',
            'imageWidth' => '200',
            'imageHeight' => '300',
            'useCaption' => true,
            'thumbOptions' => [
                'mode' => 'crop',
                'extension' => 'auto',
            ],
            'span' => 'auto',
            'type' => 'mediafinder',
        ],
    ], 'primary');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-19
      • 2021-04-16
      • 2018-05-27
      • 2020-12-15
      • 2011-04-02
      相关资源
      最近更新 更多