Codeigniter looks for libraries in the "main" folder

I created this Facebook application using ion_auth. In some browsers, when authorizing an application, it does not register the user on my server.

I checked the log files and found out about it

ERROR - 2013-06-10 00:00:01 --> Severity: Warning --> include_once(application/core/MY_Ion_auth.php): failed to open stream: No such file or directory /var/www/html/application/config/production/config.php 378 ERROR - 2013-06-10 00:00:01 --> Severity: Warning --> include_once(): Failed opening 'application/core/MY_Ion_auth.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') /var/www/html/application/config/production/config.php 378 

now line 378 config.php is like

 function __autoload($class) { if (strpos($class, 'CI_') !== 0) { @include_once(APPPATH . 'core/' . $class . EXT); } } 

ion_auth and go2 are libraries that are on automatic loading ... and they are actually in the libraries folder.

any ideas?

+4
source share
2 answers

The error loading this library is due to an older version of the __autoload method (which allows you to automatically load custom base controllers from application/core ). config.php is the correct / recommended location for this method.

A side effect of the old version is that CI tries to find in the main directory any user libraries that you load.

The solution is to use the new version of the startup method , which:

 function __autoload($class) { if (strpos($class, 'CI_') !== 0) { if (file_exists($file = APPPATH . 'core/' . $class . EXT)) { include $file; } elseif (file_exists($file = APPPATH . 'libraries/' . $class . EXT)) { include $file; } } } 
+5
source

I would suggest that you include the appropriate libraries in the constructor of your controller . For instance:

 class MyOwnAuth extends CI_Controller { /* * CONSTRUCTOR * Load what you need here. */ function __construct() { parent::__construct(); $this->load->library('form_validation'); $this->load->helper('url'); // Load MongoDB library instead of native db driver if required $this->config->item('use_mongodb', 'ion_auth') ? $this->load->library('mongo_db') : $this->load->database(); $this->form_validation->set_error_delimiters($this->config->item('error_start_delimiter', 'ion_auth'), $this->config->item('error_end_delimiter', 'ion_auth')); $this->lang->load('auth'); $this->load->helper('language'); } } /* End of class MyOwnAuth*/ 

This way you only load the libraries that are needed to run your controller. Keeps your code easy :)

0
source

Source: https://habr.com/ru/post/1485503/


All Articles