Monthly Archives: December, 2009

Phone Number Formatting Library for CodeIgnitor

18 Dec

Here is a nifty class I wrote in PHP for a side project of mine. I’m using it with CodeIgnitor, so I’m going to provide the steps to integrate it with your CodeIgnitor application quickly.

Naming Rules for custom classes:

  • File names must be capitalized. For example:  Myclass.php
  • Class declarations must be capitalized. For example:  class Myclass
  • Class names and file names must match.

Create a new file /system/application/libraries/Phoneformat.php

In line 3 that I've highlighted, you will notice that the class name is the same as the file name, without the .php extension of course.

Next, in your autoload.php file in the config folder, add the name of the file in the libraries to auto load (if you want to auto load it that is).

Now to use this to format your number, simply call the function format in the library phoneformat with the string you want to format as parameter. For example:

That's all there is to creating a library, and using it in your CodeIgnitor application. Hope this tutorial/code helped you! Lookout for more similar stuff in the future or write a comment if you need some PHP help :)

Leave a Comment

PHP, MVC and some updates

17 Dec

I’ve been coding a lot in PHP lately for a couple of side projects I’ve been working on the.  I’m trying to learn best practices while writing well structured, readable and easy to debug code as well as using the MVC approach to Web App development. This past semester at CMU I’ve got to understand some core principles behind MVC and how powerful it can be if applied/used properly!

Let me be frank now, I’ve struggled a lot with grasping MVC fundamentals in the past 2years, but I think I’ve finally cracked it after spending countless hours working on my Java assignments and side-projects.

So moving ahead, I’m now planning to share some neat tips and tricks that I’ve learnt over the past couple of months, as well as put up some code that I think can be reused in a lot of applications.

This Christmas is going to be really busy and full of  echo “fun & code”;

Leave a Comment

Great Intellects

Destiny is not a matter of chance, it’s a matter of choice. It’s not something to be waiting for, it’s something to be achieved… — Anonymous