首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Elfinder/Codeigntier在视图中使用startPath

Elfinder/Codeigntier在视图中使用startPath
EN

Stack Overflow用户
提问于 2016-05-01 10:04:59
回答 1查看 668关注 0票数 0

我刚刚集成了ELFinder,它工作得很好。我正在使用the codeigniter implementation,这就是我获得下面大部分内容的方式。我的问题是,我计划在不同的视图中使用它,那么当加载视图时,我如何选择Elfinder打开的文件夹?我正在阅读startPath,但我可能没有正确使用它。例如,在一个视图中,我可能需要它来打开"Stuff“文件夹,在另一个视图中,我可能需要它来打开"Something”文件夹。

正如教程所指出的,这是我的Files控制器中的方法( controller /Files.php):

代码语言:javascript
复制
function elfinder_init($startPath = '')
    {
      $this->load->helper('path');
      $opts = array(
        'debug' => true, 
        'roots' => array(
          array( 
            'driver' => 'LocalFileSystem', 
            'path'   => set_realpath('assets/uploads'), 
            'startPath' => $startPath,
            'URL'    => site_url('assets/uploads') . '/'
            // more elFinder options here
          ) 
        )
      );
      $this->load->library('elfinder_lib', $opts);
    }

然后假设我用以下命令创建了一个“内容”视图(views/stuff.php):

代码语言:javascript
复制
<script type="text/javascript" charset="utf-8">
jQuery(document).ready(function($) {
    var elf = $('#elfinder').elfinder({
        // lang: 'ru',             // language (OPTIONAL)
        sync: 1000,
        defaultView: 'list',
        customData: {'startPath': 'stuff'},
        url : '<?php echo site_url("Files/elfinder_init"); ?>',  // connector URL (REQUIRED)

    }).elfinder('instance');            
});
</script>

<!-- Element where elFinder will be created (REQUIRED) -->
<div id="elfinder"></div>

我也试过url : '<?php echo site_url("Files/elfinder_init"); ?>/stuff',但没有成功

下面是我的库文件(Elfinder_lib.php):

代码语言:javascript
复制
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elfinder/elFinderConnector.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elfinder/elFinder.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elfinder/elFinderVolumeDriver.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elfinder/elFinderVolumeLocalFileSystem.class.php';

class Elfinder_lib 
{
  public function __construct($opts) 
  {
    $connector = new elFinderConnector(new elFinder($opts));
    $connector->run();
  }
}
EN

回答 1

Stack Overflow用户

发布于 2016-05-01 13:24:29

我需要编辑我的Files.php控制器文件来检查$_GET请求,如下所示。

代码语言:javascript
复制
function elfinder_init()
    {
        $this->load->helper('path');

        $filePath = 'assets/uploads';
        $startPath = $filePath;
        if(isset($_GET['startPath']) && !empty($_GET['startPath'])) {
            $startPath .= '/'.$_GET['startPath'];
        }

        $opts = array(
        'debug' => true, 
        'roots' => array(
          array( 
            'driver' => 'LocalFileSystem', 
            'path'   => set_realpath($filePath),
            'URL'    => site_url('assets/uploads') . '/',
            'startPath' => $startPath
            // more elFinder options here
          ) 
        )
        );
        $this->load->library('elfinder_lib', $opts);
    }

然后,当我们像这样加载elfinder时,我可以在视图文件中使用customData选项:

代码语言:javascript
复制
<script type="text/javascript" charset="utf-8">
jQuery(document).ready(function($) {
    var elf = $('#elfinder').elfinder({
        // lang: 'ru',             // language (OPTIONAL)
        sync: 1000,
        defaultView: 'list',
        customData: {'startPath': 'something'},
        rememberLastDir: false,
        url : '<?php echo site_url("Files/elfinder_init"); ?>',  // connector URL (REQUIRED)
    }).elfinder('instance');            
});
</script>

Custom Data ReferenceExternal Links to Subfolders

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36962285

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档