简体   繁体   中英

How to access all include files in a directory in Codeigniter

I am using jquery datatable plugin which is in outside of my Codeigniter app. The datatable php editor uses namespaces.

And i have to import all editor class files inside the codeigniter controllers. So, i have to pull all files and classes inside to the "/assets/datatable/extensions/Editor/php" into my newly created controller file.

Controller file code,

// trying to import all files in this directory
$path = $_SERVER['DOCUMENT_ROOT'] . '/datatables/extensions/Editor/php';
//set_include_path(get_include_path() . PATH_SEPARATOR . $path);    
ini_set('include_path', get_include_path() . PATH_SEPARATOR . $path);
Editor::inst($db, 'contactus', 'id')
        ->fields(
                Field::inst('Position')
                ->validator('Validate::numeric', array('empty' => false)),                      Field::inst('Question')
                ->validator('Validate::notEmpty'), Field::inst('Answer')
                ->validator('Validate::notEmpty')
        )
        ->process($_POST)
        ->json();

The both "set_include_path" and "ini_set" not working in my case. It returns the below error

Fatal error: Class 'Editor' not found in /var/www/html//application/controllers/ajax.php on line 50.

Please suggest for the same.

This always works for me:

require_once($path);

instead of ini_set(). Also make sure that the path is really correct. You can use a relative path (relative to index.php). So you get something like $path = './application/libraries/custom/autoload.php'; .

(I can't post this as a comment)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM