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?
Even better, put an __autoload() at the bottom of config.php (a weird place, but trust me it's the best) and have it check in 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)
{
$lib = APPPATH . 'libraries/'. $class . EXT;
$class = APPPATH . 'classes/'. $class . EXT;
if(file_exists($class))
{
include_once $class;
}
else if(file_exists($lib))
{
include_once $lib;
}
}
}
That way you don't 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With