CodeIgniter: Ability to add HTML attributes to a table row such as class or id

It is annoying that CodeIgniter’s HTML Table class does not support the ability to add attributes to the table rows such as classes, ids and data-attr. Using something like the Twitter BootStrap you may be wanting to add classes to the rows so that you can style rows that are success, errors or warnings.

I decided that this is crazy and that the rows should work the same as the cells. I have posted two options on GitHub to overcome the problem:

  1. Extend the Table class -> https://github.com/dalehurley/codeigniter-table-rows -> add MY_Table.php to application/libraries folder
  2. Replace the Table class -> https://github.com/EllisLab/CodeIgniter/pull/2540 -> replace CI_Table.php in system/libraries folder (please comment and push for this to be pulled)
  3. Despite which solution you chose you can add the HTML attributes to the table row using 1 of two methods:

        $rows[]=array('data'=>$row, 'class'=>'warning');
        echo $this->table->generate($rows);
    

    or

        $this->table->add_row(array('data'=>$row, 'class'=>'warning'));
    

    So you may want to do something like:

        $this->load->library('table');
        foreach($people as $person)
        {
            $row_data=array($person->given_name,$person->family_name,$person->city);
            $this->table->add_row(array('data'=>$row_data, 'class'=>$person->status));
        }
        $this->table->set_heading(array('Given name','Family Name', 'City'));
        echo $this->table->generate($rows);
    

Building a URL Shortener from Scratch Using CodeIgniter

Overview

Todays post is a little longer and a lot more in-depth. Today we will look at setting up a URL shortening service with CodeIgniter similar to bit.ly etc. Yes there is 100s already out there, this is just to see how easy it is in CodeIgniter. You can create this service in minutes without breaking a sweat.

Continue reading “Building a URL Shortener from Scratch Using CodeIgniter”

Essential toolkit for a developer building a site

This is my own opinion of the keys to give you a leg up when creating a new PHP/MySQL site:

  1. Apple Mac – Go to Web Directions and it is clear web developers prefer Macs for many reasons (costs vary)
  2. MAMP Pro – So so good, so easy to use and create local hosts on the local in various locations across your Mac ($US59)
  3. Coda – The best IDE / text-editor for Mac – the all in one window is amazing ($US99)
  4. CodeIgniter – Easy to learn and very fast to develop with PHP framework (free)
  5. CodeIgniter Coda Mode – Code hinting for CodeIgniter within Coda (free)
  6. Twitter BootStrap – Basic front end layout (free)
  7. Font Awesome – Font vector images for Twitter BootStrap (free)
  8. Litmus – Get quick screenshots of your sites (from $US49 p/month)
  9. VirtualBox and Windows IE Testing VMs – Microsoft allows you to download VMs to test your site in different versions of IE (free)
  10. Sequel Pro – Awesome database GUI (free)
And a bonus is the amazing Google Apps – GMail, Google Docs, Google Analytics, Google Web Master Tools, Google Maps…(free for low volume usage)

With these tools you can get started on your next site in hours.

URL Shortening with CodeIgniter

If you are looking for a fast way to URL shorten with CodeIgniter you are in luck.

Basically you set your routes (application->config->routes.php) $route[‘404_override’] to point to the controller and action which directs shorten URLs

e.g. in you routes file:

$route['404_override']='short_links/retrive';

Then short_links has a function retrive

<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Short_links extends CI_Controller {

    function retrive()
    {
        $this->load->model('shorten_urls');//load the model which looks after the URLs
        $url = $this->uri->segment(1);//get the URL segment e.g. abc
        redirect($this->shorten_urls->get_url($url)); //lookup the original URL and redirect
    }
}