18
Feb

Most of us just want to write applications that work well, and to do it as simply and easily as we can. If you need to produce results, if you think that the details and intricacies of coding are for geeks, then you should look at CodeIgniter (CI to its friends). CI is free, lightweight, and simple to install, and it really does make your life much easier. If you are already writing code in PHP, CodeIgniter will help you to do it better, and more easily.
It will cut down on the amount of code you actually type. Your scripts will be easier to read and update.

Here are two examples (If you are already writing code in PHP, CodeIgniter will help you to do it better, and more easily ).
Imagine you are writing a database query. This is how you might write a function within your PHP programme to query a MySQL database:
$connection = mysql_connect(“localhost”,”fred”,”12345″);
mysql_select_db(“websites”, $connection);
$result = mysql_query (“SELECT * FROM sites”, $connection);
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
foreach ($row as $attribute)
print “{$attribute[1]} “;

}

Now see how a CI function would handle a similar query:
$this->load->database(‘websites’);
$query = $this->db->get(’sites’);
foreach ($query->result() as $row)
{
print $row->url
}

Compare the character counts: 244 for the traditional syntax; 112 for CI.

Now let’s imagine that you are writing a data entry form in HTML, and you want
a drop-down query box. Let’s say this drop-down query box shows three options and allows the user to select one of them. In HTML, a drop-down box can be created like this:
<select name=”type”>
<option value=”1″>www.this.com</option>
<option value=”2″>www.that.com</option>
<option value=”3″ selected>www.theother.com</option>
</select>

CI’s version is both shorter and, because it works from an array, more adapted to PHP processing:

$urlarray = array(

‘1′ => ‘www.this.com’,
‘2′ => ‘www.that.com’,
‘3′ => ‘www.theother.com’,

);
$variable .= form_dropdown(‘url’, $urlarray, ‘1′);

In HTML, you need to type 154 characters; in CI, 128.

Imagine that you’ve just written a menu page, with lots of hyperlinks to other pages in your site. They are all in the traditional HTML format:
<a href=”http://www.mysite.com/index.php/start/hello/fred
“>say hello to Fred</a>

Then, you decide to move the site to another URL. That means you have to go painstakingly through your code, looking for each URL, and re-writing it, or else none of your links will work.
CI gives you a simple function to write hyperlinks like this:
echo anchor(start/hello/fred, Say hello to Fred);

if you want to compareĀ  PHP framework:http://www.zflinks.com/Zend-Framework-and-Other-Frameworks/Taking-a-look-at-ten-different-PHP-frameworks-l8.html
(source:Upton, David. 2007. CodeIgniter for Rapid PHP Application Development. Packt Publishing, Birmingham.)

This entry was posted on Wednesday, February 18th, 2009 at 6:04 am and is filed under Codeigniter. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or TrackBack URI from your own site.

One Response to "Introduction to Codeigniter"

  1. 1 viagra
    August 19th, 2009 at 7:00 am  

    Incredible site!

Leave a reply

Name (*)
Mail (*)
URI
Comment