0

I am trying to integrate ckeditor and ckfinder to a project using yii2. I have placed both ckeditor and ckfinder folder in root/vendor and made necessary adjustments, ckeditor is working fine, ckfinder also showing the file browser popup with 'Browser server' button. But whenever I click on the browse button its not opening the file selector popup, instead showing a page not found error.

I have tried to integrate ckfinder writing following lines of code in ckeditor/config.js:

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';

But I haven't found a solution.

Can anyone please help me fix that issue?

devlin carnate
  • 8,309
  • 7
  • 48
  • 82
  • 1
    A few questions: Which version of CKFinder do you use? Could you clarify which browse button doesn't work? Is this a custom button on the page that starts the file browser? Please also check if CKFinder samples works correctly. – zaak Jun 20 '16 at 15:24
  • 1
    Maybe this help https://github.com/2amigos/yii2-ckeditor-widget – Vitaly Jun 20 '16 at 17:14
  • The 'Browse Server' button is in the popup for adding images/files to the content. The popup opens when the image icon is clicked from the editor. I just moved the ckeditor and ckfinder folder from 'root/vendor' to 'root/web' and made other settings as before and the issue is now fixed. It seems in yii2 no 3rd party files are directly accessible outside 'web' directory unless it is formatted as an yii extension. – RP-ind-Dev Jul 01 '16 at 07:26

1 Answers1

0

I was create Custom CKEditorAsset in yii2 like this:

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();
    }
}
morteza khadem
  • 346
  • 3
  • 8