yii2 ckeditor缺少图像源URL

时间:2017-11-29 07:19:55

标签: yii2 ckeditor

我正在为yii2 https://packagist.org/packages/wadeshuler/yii2-ckeditor-cdn

使用此ckeditor扩展程序

我创建了目录后端/ web / uploads / images并为他们提供了权利777

我像这样配置了backend / config / main.php

'modules' => [
        'ckeditor' => [
            'class' => 'wadeshuler\ckeditor\Module',    // required and dont change!!!

            'uploadDir' => '@app/web/uploads',    // must be file path (required when using filebrowser*BrowseUrl below)
            'uploadUrl' => '@web/uploads',        // must be valid URL (required when using filebrowser*BrowseUrl below)

            // These are basically passed to the `CKEDITOR.replace()`
            'widgetClientOptions' => [

                'filebrowserImageBrowseUrl' => '/ckeditor/default/image-browse',
                'filebrowserImageUploadUrl' => '/ckeditor/default/image-upload',
            ]
        ],

    ],

加入表格

use wadeshuler\ckeditor\widgets\CKEditor;
<?= $form->field($model, 'body')->widget(CKEditor::className()) ?>

当我上传图片并单击“将其发送到服务器”时,它不会上传,当我点击“确定”时,它表示图像源网址丢失。

也许以前有人遇到过这个问题? 顺便说一句,如果我删除这些行

//'uploadDir' => '@app/web/uploads',    // must be file path (required when using filebrowser*BrowseUrl below)
        //'uploadUrl' => '@web/uploads',        // must be valid URL (required when using filebrowser*BrowseUrl below)

没有任何改变。同样的错误。

1 个答案:

答案 0 :(得分:0)

它可能有点过时了,但谁知道有人可能偶然发现同样的问题,尽管我的框架有点不同。我使用codeigniter并尝试将其与ckeditor上传图片插件集成,但你应该明白,因为ckeditor的返回值是相同的。

here是我找到的解决方案,请参阅链接并参见示例3部分

看起来像这样:

// Required: anonymous function reference number as explained above.
$funcNum = $_GET['CKEditorFuncNum'] ;
// Optional: instance name (might be used to load a specific configuration file or anything else).
$CKEditor = $_GET['CKEditor'] ;
// Optional: might be used to provide localized messages.
$langCode = $_GET['langCode'] ;

// Check the $_FILES array and save the file. Assign the correct path to a variable ($url).
$url = '/path/to/uploaded/file.ext';
// Usually you will only assign something here if the file could not be uploaded.
$message = '';

echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction($funcNum, '$url', '$message');</script>";

你应该注意filebrowserUploadUrl选项必须指向处理上传图像的yii函数,在这种情况下看起来像上面的示例代码。并且不要忘记在uploadimage个选项上添加filebrowserextraPlugins

希望有所帮助。