-
Notifications
You must be signed in to change notification settings - Fork 7
Dynamic roots
Alex Yashkin edited this page Jun 13, 2017
·
1 revision
Inspired by issue #2. Setting root path dynamically in widget.
- Create custom action instead
ConnectorAction
:
public function actionConnector()
{
$path = \Yii::$app->request->getQueryParam('path');
$path = trim($path, '/');
// todo: clean and validate path
if (empty($path)) {
$path = 'uploads';
}
$options = [
'roots' => [
[
'driver' => 'LocalFileSystem',
'path' => Yii::getAlias('@webroot') . DIRECTORY_SEPARATOR . $path,
'URL' => Yii::getAlias('@web') . '/' . $path . '/',
'mimeDetect' => 'internal',
'imgLib' => 'gd',
'accessControl' => function ($attr, $path) {
return (strpos(basename($path), '.') === 0) ? !($attr == 'read' || $attr == 'write') : null;
},
],
],
];
\Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
(new \elFinderConnector(new \elFinder($options)))->run();
}
- Extend CKEditorAction:
class CustomCKEditorAction extends \alexantr\elfinder\CKEditorAction
{
public function run()
{
$path = \Yii::$app->request->getQueryParam('path');
$this->connectorRoute = [$this->connectorRoute, 'path' => $path];
return parent::run();
}
}
- Set news class in CKEditor config:
'ckeditor' => [
'class' => CustomCKEditorAction::className(),
'connectorRoute' => 'connector',
],
- Set path in CKEditor widget:
'filebrowserBrowseUrl' => yii\helpers\Url::to(['elfinder/ckeditor', 'path' => 'uploads/pictures/cats']),