如何在 yii2 中为 elfinder 设置 URL? [英] How to set URL for elfinder in yii2?
问题描述
我在 yii2 框架中使用这个模块但无法设置正确的 URLhttps://github.com/simialbi/yii2-elfinder
I am using this module in yii2 framework but unable to set the correct URL https://github.com/simialbi/yii2-elfinder
'connectionSets' => [
'default' => [ // like elfinder roots
[
'class' => 'simialbi\yii2\elfinder\ElFinderConfigurationLocalFileSystem',
'path' => '@webroot/uploads',
'URL' => '@web/file/files' // HERE PROBLEM
]
]
],
这就是我定义 URL 的方式 'URL' =>'@web/file/files'
其中 file
是我的控制器, files
是我的 action .你能告诉我这个 URL 显示是如何在 yii2 基本模板中传递的吗.
This is how I have defined URL 'URL' => '@web/file/files'
where file
is my controller and files
is my action .
Could you please let me know how exactly this URL show be passed in yii2 basic template .
127.0.0.1:8080/project/elfinder/proxy/index?baseUrl=QHdlYi9maWxlL2ZpbGVz&path=/NewFolder/file_example_PNG_500kB.png&_t=1587811929
推荐答案
我刚刚想通了.第 1 步:- 您需要正确设置 URL 管理器
I just figured it out . Step 1 :- You need to set the URL managers properly
'urlManager' => [
'controller/action/<file:.*>' => 'controller/action',
]
第 2 步:- 创建一个动作并添加此代码
Step 2 :- Create an action and add this code
public function actionYourActionName($file)
{
$image_path = YOUR_UPLOAD_PATH . basename($file);
if (file_exists($image_path)) {
return \yii::$app->response->sendFile($image_path, $file, [
'inline' => true //OPTIONAL
]);
}
return "What exception you want to throw";
}
这篇关于如何在 yii2 中为 elfinder 设置 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!