A better autoloader

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
*/
function __autoloader($class_name)
{

//class directories
$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
return;
}
}

}

spl_autoload_register(‘__autoloader’);

 

Ajax on Steriods in CodeIgniter

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…

https://github.com/IgnitedCoder/ci_pheryphp

Code on!

Brendan

Meditation: This code is pissing me off.

Meditation Time: 15 Minutes

We’ve all been there. You get your hands on a legacy piece of code or code written by someone else could’ve and should’ve been simpler but it isn’t.

When it comes to coding we’ve all gathered moss or garbage from the past that now serve as our principles and beliefs, some of these principles/beliefs have served us well, and some not so well. Your geek mind has never been given the freedom to throw out the garbage, perhaps do some house cleaning.

Given the opportunity “the geek mind” will run wild, like a horse free of its reigns, let it run free… Allow all of your past beliefs, principles and ideas to flow effortlessly through the geek mind. Your only job while this is happening is to sit back and silently observe your geek mind at work.

Become an observer of the geek mind. See the ideas, thoughts about the code, and past principles about what Is and what isn’t good code and allow it all to flow.

What to expect.

You will want to fix the code immediately, “the problem solver” will appear. Don’t act on it, simply remain as the ever present observer.

Codeigniter Environments

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?

Heres how:

  1. Inside your application/config folder simple add 2 new folders as follows
    1. application/config/production
    2. application/config/development
  2. Next
    1. 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.
  3. 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');

Replace with:

$env = $_SERVER['HTTP_HOST'] == 'yourlocaldevdomain.dev' ? 'development' : 'production';
define('ENVIRONMENT', $env);

Voila, thats it – CI will now use either the production or development folders based on your host domain.

Enjoy,

Brendan (IgnitedCoder)

Professionally Speaking

Is it me or has the idea of being professional been supplanted? I’ve now had more than a few encounters that could’ve been far more pleasant if the idea of professionalism was alive and well.

I’m not “self-righteously” confirming my own professionalism  in every situation but I do give it my best shot.

For one thing I try to communicate as often and as clearly as I can with my clients. I try never to make my clients wait for something important. All I can really ask for in return is the same courtesy.

Don’t blow off communicating “even when its difficult to say things openly” and if you do have to blow off communication at least do it professionally…

e.g. “Hey sorry we can’t talk now, will try to touch base later. Apologies, Joe Blogs”.

I can deal with a one liner response, it lets me know I’m not being ignored and that you’re busy with other things but I am on the list of people you need to talk to about your project.

This is not to case with some folks… they go dark, don’t communicate or respect your time and they expect the highest level of professionalism and commitment from you.

Is this really how much business has changed?
Are we really moving so fast that sitting down to write a brief email explaining in a few sentences why we won’t be able to talk as planned.

I’m asking you to hold fast the idea of professionalism as an essential part of doing business. Its not even a novel idea. I think business relationships would be far better, financial transactions would flow with ease and we’d all have a solid foundation on how we deal with each other….

With Respect,

Brendan