【问题标题】:How to disable or remove Yii2 redactor Image and file button?如何禁用或删除 Yii2 编辑器图像和文件按钮?
【发布时间】:2018-05-28 06:55:34
【问题描述】:

我正在使用来自HereYii2 Redactor。我想删除Image and File Upload

查看代码:

<?= $form->field($model, 'reason')->widget(
\yii\redactor\widgets\Redactor::className(), [])

 ?>

截图

【问题讨论】:

    标签: php yii2 redactor


    【解决方案1】:

    如果您想隐藏所有 Redactor 实例的按钮,您可以将其添加到模块配置中

    'modules' => [
        'redactor' => [
            'class' => 'yii\redactor\RedactorModule',
            'widgetClientOptions' => [
                'buttonsHide' => ['image','file'],
            ]
        ],
    ],
    

    否则,您可以将其添加到个人通话中

    <?= $form->field($model, 'reason')->widget(\yii\redactor\widgets\Redactor::className(), [
        'clientOptions' => [
            'buttonsHide' => ['image','file'],
        ]
    ])?>
    

    【讨论】:

    • 请注意,隐藏此按钮不会禁用上传功能 - 如果控制器收到有效请求,它仍将处理上传。这可能是安全漏洞(任何人都可以将文件上传到您的服务器)。
    • @rob006 你有更好的解决方案吗?
    【解决方案2】:

    在这个库中,你只需要更新路径中的文件,即 Redactor.php yii2-redactor/widgets/Redactor.php

    现在更新方法 defaultOptions评论或删除从 92 到 103 的行 以下是这些行的代码:

    $this->setOptionsKey('imageUpload', $this->module->imageUploadRoute);
            $this->setOptionsKey('fileUpload', $this->module->fileUploadRoute);
            $this->clientOptions['imageUploadErrorCallback'] = ArrayHelper::getValue($this->clientOptions, 'imageUploadErrorCallback', new JsExpression("function(json){alert(json.error);}"));
            $this->clientOptions['fileUploadErrorCallback'] = ArrayHelper::getValue($this->clientOptions, 'fileUploadErrorCallback', new JsExpression("function(json){alert(json.error);}"));
            if (isset($this->clientOptions['plugins']) && array_search('imagemanager', $this->clientOptions['plugins']) !== false) {
                $this->setOptionsKey('imageManagerJson', $this->module->imageManagerJsonRoute);
            }
            if (isset($this->clientOptions['plugins']) && array_search('filemanager', $this->clientOptions['plugins']) !== false) {
                $this->setOptionsKey('fileManagerJson', $this->module->fileManagerJsonRoute);
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多