CKEditor CKFinderを使ってS3からの呼び出しやId毎にDirectoryを分ける方法
2026/05/18
ckfinderはだと直接ディレクトリを見に行くためDBからunique_idを使い検索することができません。
なのでOSS内を直接変更する必要があります。ちなみに使用FWはCakePHPです。
今回自分がやったやり方ですが、最初にcakephpでApi用のcontrollerにシンプルにuser情報をreturnするだけのメソッドを作ります。
public function getUserCkfinder()
{
if ($this->getRequest()->is('ajax'))
{
return $this->response->withStringBody(json_encode($user, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS));
}
}
シンプルですね、失敗した処理とか割愛です。
次に./ckfinder/getUserInformation.jsってのを作りこれも中身はシンプル
$(function () {
const host = location.hostname;
const protocol = location.protocol
const url = protocol + '//' + host + '/mypage/api/getUserCkfinder';
$.ajax({
url: url,
type: 'GET',
dataType: 'json',
})
.done(function(data) {
CKFinder.start({id: data.id, pass: 'user_id'});
})
.fail(function() {
console.log("ajax通信に失敗しました");
});
});
デフォルトでは CKFinder.start() ってのが ckfinder.htmlにあるのですが、それをAJAX通信成功後に使うようにすれば
/core/~ から降りてったconnector.phpで処理してくれるって流れです。
require_once DIR . ‘/vendor/autoload.php’;
use CKSource\CKFinder\CKFinder;
$ckfinder = new CKFinder(DIR . ‘/../../../config.php’);
$ckfinder->run();
~