-
Notifications
You must be signed in to change notification settings - Fork 10
/
ElFinderWidget.php
46 lines (38 loc) · 1.08 KB
/
ElFinderWidget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace zxbodya\yii2\elfinder;
use Yii;
use yii\base\Exception;
use yii\base\Widget;
use yii\helpers\Json;
use yii\helpers\Url;
class ElFinderWidget extends Widget
{
/**
* Client settings.
* More about this: https://github.com/Studio-42/elFinder/wiki/Client-configuration-options
* @var array
*/
public $settings = array();
public $connectorRoute = false;
public function init()
{
if (empty($this->connectorRoute)) {
throw new Exception('$connectorRoute must be set!');
}
$this->settings['url'] = Url::toRoute($this->connectorRoute);
$lang = Yii::$app->language;
if (strpos($lang, '-')) {
$lang = substr($lang, 0, strpos($lang, '-'));
}
$this->settings['lang'] = $lang;
}
public function run()
{
$id = $this->getId();
$settings = Json::encode($this->settings);
$view = $this->getView();
ElFinderAsset::register($view);
$view->registerJs("$('#$id').elfinder($settings);");
echo "<div id=\"$id\"></div>";
}
}