yiidoc / yii2-redactor

Extension Redactor WYSIWYG for Yii2 framework
BSD 3-Clause "New" or "Revised" License
186 stars 87 forks source link

遇到一处问题不知道是不是作者故意这样做的 #90

Open anyeshe opened 5 years ago

anyeshe commented 5 years ago

我在模板中这样使用本项目:

<?= $form->field($model, 'process')->widget(yii\redactor\widgets\Redactor::className(), [ 'clientOptions' => [ 'imageUploadParam' => 'UploadForm['.\backend\models\UploadForm::UPLOAD_KEY_KNOW.']' ], ]) ?>

我用模板上自定义的配置覆盖配置文件的配置,下面是配置文件的配置:

'redactor' => [ 'class' => 'yii\redactor\RedactorModule', 'uploadDir' => '@static/project/', 'uploadUrl' => '@static/project/', 'imageAllowExtensions' => ['jpg','png','jpeg'], 'imageUploadRoute' => '/tool/upload', 'widgetClientOptions' => [ 'lang' => 'zh_cn', 'dragUpload' => true, 'clipboardUpload' => true, 'imageCaption' => true, 'imageUploadParam' => 'UploadForm[detail_image]', 'minHeight' => '300px', 'buttons' => ['bold', 'italic', 'deleted', 'lists', 'image', 'line', 'underline'], 'plugins' => ['fontcolor', 'fullscreen'], 'convertLinks' => false, ], ],

但是项目中源代码文件(yiidoc/yii2-redactor/widgets/Redactor.php)中init函数调用如下:

public function init() { $this->defaultOptions(); ... } protected function defaultOptions() { $this->options = ArrayHelper::merge($this->options, $this->module->widgetOptions); $this->clientOptions = ArrayHelper::merge( $this->clientOptions, $this->module->widgetClientOptions);

这样ArrayHelper::merge是没办法用自定义配置覆盖默认配置的。在模板中也就不能自定义配置。如果把 ArrayHelper::merge参数调换位置就可以了(因为默认$this->options是个空数组)。