I've been working from home today, which was something of a novelty! No one was in the office so I've been working on a website design at home (sort of a secondary project there).

For most of the websites (including my personal one) I build I make use of a framework called Kohana. It's a very nice, standard efficient and clean framework; however it requires PHP5 (which is still widely unsupported). That's not a problem for most of the sites I work with (my main host Servage supports PHP5 thank goodness) but of course this project requires PHP4. As a result I have shifted back ot using another framework called Code Igniter. CI is similar to Kohana (in fact the latter was born out of CI) but not quite *as good*.

It just feels all clunky and stodgy to use. I dont know if that is because of how it is coded, the aging documentation (meanign Im lost on the advanced functions) or (most likely) PHP4 being crap.

On the positive side I have managed to put together a semi-basic user auth system. I based it off this quick and easy login library Simple Login. I added some the ability to load a user from the database and an extra field for a persons "real name" (I always find that useful). I also cleaned up some ageing syntax. On top of that I've laid a simple (but nice) user model to act as an *abstraction* layer to the library and to keep in line with the MVC (Model View Controller) requirements.

It's not finished yet, I want to add user roles to it and a form of authentication at the controller level. Hopefully I'll upload the source over the weekend when I get it working properly.

However I do want to share a sort-of neat piece of code I came up with. This allows you to grab the user from the database either by passing the function a userid (integer) or a username (string). Pretty cool I think :D

// function to load user data and return it as an array
function load_array($user)
{
    $this->CI =& get_instance();
    // check if we have an int or string
    if(is_numeric($user))
    {
        // int, so lets lookup via their ID
        $query = $this->CI->db->get_where('users', array('id' => $user));
    }
    else
    {
        // string, so we lookup via the username
        $query = $this->CI->db->get_where('users', array('username' => $user));
    }
    // and then return the results if we have any
    if ($query->num_rows() > 0)
    {
        return $query->row_array();
    }
    return false;
}
Hardly rocket science but pretty handy nonetheless :)