0

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

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

当我将名称设置为 justphoto我得到"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;
            }

        });
    }
}
4

1 回答 1

0

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');
于 2018-04-05T09:11:09.913 回答