Category Archives: tutorial

Multiple Argument in CodeIgniter’ s Form Validation Callback

CodeIgniter have a powerful form validation class out of the box. We also can create our validation method using a callback. By default, “callback” just accept 1 argument. I didn’t found in user guide, how to make callback accept more than 1 argument.

But, after doing little googling i found a way to do it. For example:

$val->set_rules('field', 'Field Name', "trim|xss_clean|required|callback__example_callback[{$argument}]")
......

function _example_callback($default_argument, $argument) {

.......

See the bold text. Done. 🙂

Hide Friend or Apps From News Feed on Facebook

Today, facebook and twitter became the most popular social network. Almost all of my friend have facebook and or twitter. Social Network became the next world. We posted on someone’s wall, we share anything in status/tweet, we comment on someone’s status /tweet. It’s like another world in our ordinary life.

But somehow, we want to not following or see someone’s updates/tweet. In twitter, we can just unfollow. And we can remove friends from facebook, but in facebook there is so many consideration. 🙂

Continue reading

Send SMS using Python Gammu

Gammu is a command line utility for controlling a phone (or modem) written in C. Gammu can be used for phone management software or maybe a SMS Gateway. Gammu can manage SMS, MMS, Phonebook, Calendar, phone’s file system and Call.

Today, i try to install Gammu and Python Gammu on Ubuntu 10.10 Maverick. Then, i write some code to send sms using command line.
Continue reading

Enable Mod Rewrite on Snow Leopard

After enable Apache and PHP (also installing MySQL) on my macbook, i want to enable mod rewrite (Rewrite engine) .  From wikipedia, Mod rewrite (rewrite engine) described as  software that modifies a web URL‘s appearance (URL rewriting). Rewritten URLs (sometimes known as short, fancy URLs, or search engine friendly – SEF) are used to provide shorter and more relevant-looking links to web pages. The technique adds a degree of separation between the files used to generate a web page and the URL that is presented to the world.

By default, mod rewrite has been enabled. But we need edit some configuration before we can use it.

  1. Go to /etc/apache2/httpd.conf than edit the <Directory /> section. Change AllowOverride to All
        AllowOverride All
  2. Edit /etc/apache2/users/youruser.conf, change to this:
    <Directory "/Users/youruser/Sites/">
    Options Indexes MultiViews FollowSymlinks
    AllowOverride All
     Order allow,deny
     Allow from all
    </Directory>
    
    <Directory "/Users/youruser/Sites/*/">
     Options Indexes MultiViews FollowSymLinks
    </Directory>
  3. Done. 🙂

Apache PHP MySQL on Mac OS X 10.6

By default, Mac OS X come with preinstalled Apache and PHP. But for a while, i’m using XAMPP for Mac in my macbook because in my first time using Mac OS, i don’t know about it.

Yesterday, i tried to using preinstalled Apache and PHP, also adding MySQL. For enable Apache, it just take a click. Go to System Preferences -> Sharing
Continue reading

Sub Query in CodeIgniter

Few month ago, i posted about sub query in codeigniter here. And today i’ve found another way. It using active record class in codeigniter. For example:

$this->db->select('(SELECT SUM(payments.amount) FROM payments WHERE payments.invoice_id=4') AS amount_paid', FALSE);
$query = $this->db->get('mytable');

Just put ‘FALSE’ to second parameter in select() function. $this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.

So simple. Isn’t it?:D

$this->load->view()

When you are using codeigniter, you will use function $this->load->view to load your ‘view’. In codeigniter user guide, a view is described as simply a web page, or a page fragment, like a header, footer, sidebar, etc. In fact, views can flexibly be embedded within other views (within other views, etc., etc.) if you need this type of hierarchy.

In my last project, some fragment on view is loaded in every page. They are header, footer and sidebar. And the content is dynamic. I don’t want to load views for every page. So i write a function in a library (or you can also extends the controller) to handle loading views for every page.
Continue reading