简体   繁体   中英

Codeigniter looking for libraries in “core” folder

I created this Facebook app using ion_auth. In some browsers when you authorize the app it does not log the user in on my server.

I checked the log files and found out this

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 the config.php line 378 is like

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

ion_auth and go2 both are libraries that are on auto-load ... and they are actually in libraries folder.

any ideas?

This libraries loading error is related to an older version of the __autoload method (which allows you to autoload custom base controllers from within application/core ). config.php is the correct / recommended location for this method.

A side effect of the old version is that CI attempts to find in the core directory any custom libraries you load.

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

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;
        }
    }
} 

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

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 are only loading libraries that are essential for your controller to run. Keeps your code lightweight :)

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