如何将ckfinder与yii2集成

时间:2016-06-20 14:59:11

标签: yii2 ckfinder

我正在尝试使用yii2将ckeditor和ckfinder集成到一个项目中。 我已经在root / vendor中放置了ckeditor和ckfinder文件夹并进行了必要的调整,ckeditor工作正常,ckfinder还显示文件浏览器弹出窗口'浏览器服务器'按钮。但每当我点击浏览按钮时,它都不会打开文件选择器弹出窗口,而是显示找不到页面错误。

我试图在ckeditor / config.js中集成ckfinder编写以下代码行:

config.filebrowserBrowseUrl = 'hostname/vendor/ckfinder/ckfinder.html';
config.filebrowserImageBrowseUrl = 'hostname/vendor/ckfinder/ckfinder.html?type=Images';
config.filebrowserFlashBrowseUrl = 'hostname/vendor/ckfinder/ckfinder.html?type=Flash';
config.filebrowserUploadUrl = 'hostname/vendor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files';
config.filebrowserImageUploadUrl = 'hostname/vendor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images';
config.filebrowserFlashUploadUrl = 'hostname/vendor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash';

但我还没有找到解决方案。

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

我在yii2中创建了Custom CKEditorAsset,如下所示:

namespace vendor\yiif\ckeditor;


use iutbay\yii2kcfinder\KCFinder;
use iutbay\yii2kcfinder\KCFinderAsset;

class CKEditorAsset extends \dosamigos\ckeditor\CKEditorAsset
{
    public $depends = [
        'yii\web\YiiAsset',
        'yii\web\JqueryAsset',
        //'iutbay\yii2kcfinder\KCFinderAsset'
    ];

    public function init()
    {
        $register = KCFinderAsset::register(\Yii::$app->view);
        $kcfinderUrl = $register->baseUrl;

        \Yii::$app->view->registerJs(<<<js
            CKEDITOR.config.filebrowserBrowseUrl="$kcfinderUrl/browse.php?opener=ckeditor&type=files";
            CKEDITOR.config.filebrowserUploadUrl="$kcfinderUrl/upload.php?opener=ckeditor&type=files";
js
    );



        // kcfinder options
        // http://kcfinder.sunhater.com/install#dynamic
        $kcfOptions = array_merge(KCFinder::$kcfDefaultOptions, [
            'uploadURL' => \Yii::getAlias('@web/uploads/modules/ckfinder'),
            'uploadDir'=>\Yii::getAlias('@app/web/uploads/modules/ckfinder'),
            'access' => [
                'files' => [
                    'upload' => true,
                    'delete' => false,
                    'copy' => false,
                    'move' => false,
                    'rename' => false,
                ],
                'dirs' => [
                    'create' => true,
                    'delete' => false,
                    'rename' => false,
                ],
            ],
        ]);

// Set kcfinder session options
        \Yii::$app->session->set('KCFINDER', $kcfOptions);
        parent::init();
    }
}