代码之家  ›  专栏  ›  技术社区  ›  Steve M

使用$widget->addFields将fileupload字段添加到十月CMS后端?

  •  0
  • Steve M  · 技术社区  · 8 年前

    尝试添加类型为的表单字段 fileupload 和模式 image 在十月CMS后端使用插件访问特定页面,但出现错误。文本、下拉列表等类型工作正常。

    当我将字段名称设置为 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;
                }
    
            });
        }
    }
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   Steve M    8 年前

    这个 fileupload 无法通过将类型添加到静态页面 addFields 目前。这个 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');
    
    推荐文章