Welcome Guest, Not a member yet? Register   Sign In
loading user libraries question?
#1

[eluser]dsims[/eluser]
I was having a problem comprehending loading user classes and Have been using this in my libraries folder, It is just a simple autoload function and gets included in the index.file of the application i.e. /public_html/index.php
I am only using it on a development server but it seems to do what I want.
Code:
// file location application/libraries/Autoload.php
<?php
spl_autoload_extensions('.php');
function classLoader($class)
{
    $file = str_replace('_', '/', $class) . '.php';
    if(is_file(dirname(__FILE__) . DIRECTORY_SEPARATOR . $file)){
        include $file;
    }
}
spl_autoload_register('classLoader');
on public_html/index.php
Code:
include APPPATH.'libraries/Autoload.php';
require_once BASEPATH.'codeigniter/CodeIgniter'.EXT;
I use this because basically I didn't feel like renaming all my classes. If their is something wrong with this method please advise?




Theme © iAndrew 2016 - Forum software by © MyBB