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);
    

PHP Multi-thread Asynchronous Process Manager

PHP Multi-thread Asynchronous Process Manager

I have been build some background apps recently which need to do a lot of repetitions (think 100,000 times the same task which takes about 0.25 to 1 second to execute, of which most of it is waiting for the remote server to respond). Since these are daily and are not that server intensive it made sense to run them concurrently so instead of taking the good part of the day it just takes a few hours. I noticed on the proc_open page there was a very nice solution by Matou Havlena of havlena.net.

Continue reading “PHP Multi-thread Asynchronous Process Manager”

Password Hashing – With some smart salt

Password Hashing – With some smart salt

Basic hashing of passwords is poor. LinkedIn should have expected that one day that their password list would be stolen and when that happened it should have been hashed better so a standard dictionary could not reverse the passwords. Tthe LinkedIn passwords were leaked all over internet and with the help of crowd-sourced hackers the passwords were easily reversed back from SHA-1 hashes substrings to the plain text passwords. With tools like John the Ripper social hackers like Francois Pesce was able to reverse over 2 million LinkedIn passwords.

Continue reading “Password Hashing – With some smart salt”

Getting the directory listing using PHP's Glob Function

The other day the new developer  in my office wanted to get a directory listing using  PHP as he was writting a new plugin for WordPress. To his surprise this is really easy with the glob() function:

<?php
foreach (glob("*") as $filename) {
    echo $filename . 'size ' . filesize($filename) . 'n';
}

 

Glob allows you to use patterns similar to those when you are using the ls command in Terminal and returns the file list as an array.

Get the HTML of any page with PHP

Quick tip: if you want to get the HTML for any web page you can use the PHP function file_get_contents(). To see the HTML in your web browser wrap the htmlentities  function around the file_get_contents() function.

<?php

echo htmlentities(file_get_contents('http://example.com'));

Which returns:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>IANA &mdash; Example domains</title>
	<!-- start common-head -->
	<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" type="text/css" href="/_css/2008.1/reset-fonts-grids.css" />
	<link rel="stylesheet" type="text/css" media="screen" href="/_css/2008.1/screen.css" />
	<link rel="stylesheet" type="text/css" media="print" href="/_css/2008.1/print.css" />
	<link rel="shortcut icon" type="image/ico" href="/favicon.ico" />
	<script type="text/javascript" src="/_js/prototype.js"></script>
	<script type="text/javascript" src="/_js/corners.js"></script>
	<script type="text/javascript" src="/_js/common.js"></script>
	<!-- end common-head -->

</head>
<body>
	<!-- start common-bodyhead -->
....
	<!-- end common-bodytail -->

</body>
</html>

 

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.