I’ve seen a few folks refer to an old autoload piece of code written a long time ago in a galaxy far far away. Anyway this is a newer more updated autoloader function you can add to the bottom of your config.php file.
Note the array you can use to define multiple auto-load locations so you don’t have to keep everything in core.
Stick this code at the bottom of your config.php file. Or, make a file called myautoloader.php and include it in your config.php file for a cleaner setup.
* Autoloader function
* @param $class_name
* @return void
$directories = array(
APPPATH . ‘core/’,
//add more autoloading folders here… and you’re done.
//for each directory
foreach($directories as $directory)
//see if the file exsists
if(file_exists($directory.$class_name . ‘.php’))
require_once($directory.$class_name . ‘.php’);
//only require the class once, so quit after to save effort (if you got more, then name //them something else
Sometime ago I decided to give phery-php a try. What sucked though was that it was very difficult to use in CodeIgniter and Kohana, two frameworks I had grown to love and use often. Result, a phery php library for codeigniter and a class I could use in Kohana “now retired”.
Anyway, heres a link to the CodeIgniter Library…
This is going to be a quick post… actually all my codeigniter related posts will be quick hints and tips to make your codeigniter development easier.
This particular tip relates to productions vs development environments. Did you know that seperating production/development environments it CI is really easy?
- Inside your application/config folder simple add 2 new folders as follows
- Grab a copy of autoload.php, database.php and email.php if you have a email config file and place them into each of the folders /production & /development respectively.
- Time to edit your index.php file in the root folder of your site.
Find the following line of code in your index.php file:
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
$env = $_SERVER['HTTP_HOST'] == 'yourlocaldevdomain.dev' ? 'development' : 'production';
Voila, thats it – CI will now use either the production or development folders based on your host domain.