forked from Studio-42/elFinder
-
Notifications
You must be signed in to change notification settings - Fork 7
Integration with Codeigniter 2
lexx27 edited this page Nov 11, 2011
·
3 revisions
- Place the css and js files according to the installation instructions (Install)
- Copy the php directory from the archive to your application’s libraries directory.
- Rename this folder from php to elfinder.
- Create a new file in the libraries directory with the name Elfinder_lib.php. I added __lib _in order to avoid conflict with elfinder’s classes.
- Treat Elfinder_lib.php as an ordinary CI library and add the following code inside:
<?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();
}
}
- Now you need to create a controller method in order to call it from your javascript. This will be a method of your choice. I will name the controller ex_cont and the method elfinder_init() for this example.
- Inside this method you will add part of the connectors code, and it will look like this:
<?php
function elfinder_init()
{
$this->load->helper('path');
$opts = array(
// 'debug' => true,
'roots' => array(
array(
'driver' => 'LocalFileSystem',
'path' => set_realpath('yourfilespath'),
'URL' => site_url('yourfilespath') . '/'
// more elFinder options here
)
)
);
$this->load->library('elfinder_lib', $opts);
}
-
Replace "yourfilespath" with the name of your files folder.
-
The last step is to initialize the elFinder through javascript and add the html element. Follow the original documentation again (Install) under the Initialize file manager section. The only thing you should notice is the url option which should be something like http://yoursite/ex_cont/elfinder_init
By passing variables to you elfinder_init method you can achieve some great stuff like open the browser to a post’s folder or to a user’s place. Or adding multiple roots dynamically etc.