views:

546

answers:

3

I am considering using CodeIgniter as the framework for my next web-application. However, I already have a large number of helper classes and data structures defined. I could add them to the application's library but I have to rename a large number of files and classes' name to match the criterion

Can I just directly include files as in working on a normal web application, bypassing load->library()? Or is the library reserved for commonly reused classes?

+1  A: 

You can directly include them if you wish. The loading functionality makes things easier, but nothing is stopping you from doing a standard include in php. I've done it several times with third-party classes.

Kohana (a fork of CodeIgniter) is worth checking out if you are still looking for a good PHP framework. In my opinion, it is much better than CodeIgniter.

Sam Soffes
+1  A: 

You don't need to use CodeIgniter's class loaders, you can also require them as you would in any web app, or wrap them in CI-loadable wrappers. In my own projects, I have a few small stand-alone libraries I require from my base controller, and I wrap a few public libraries (like Markdown) for use as a standard CI library.

Bruce Alderson
A: 

Even better, put an __autoload() at the bottom of config.php (a weird place, but trust me its the best) and have it checking application/classes/ then check application/functions.

/*
| -------------------------------------------------------------------
|  Native Auto-load
| -------------------------------------------------------------------
| 
| Nothing to do with config/autoload.php, this allows PHP autoload to work
| for controller types and some third-party libraries.
|
*/
function __autoload($class)
{
    if(strpos($class, 'CI_') !== 0)
    {
        $class = APPPATH . 'classes/'. $class . EXT;
        $lib = APPPATH . 'libraries/'. $class . EXT;

        if(file_exists($class))
        {
            include_once( $class );
        }

        else if(file_exists($lib))
        {
            include_once( $lib );
        }
    }
}

That way you dont need to worry how things are loaded. Use the core libraries as expected and use your classes without including them at all. You can even start moving your classes over to be libraries without needing to worry too much about naming conventions or the loader, and libs can be static, singleton, whatever using this method.

Phil Sturgeon