Add Additional Cookie on WordPress

wordpress-logo
Today I realize that the simple setcookie("sevisitor", 1, time()+3600); would not work perfectly on WordPress especially when your combine it with WordPress permalink. Here a simple hack that you can opt for if you want to set in multiple WordPress environment (especially for plug-ins and themes).

setcookie("sevisitor", 1, time()+3600,
    SITECOOKIEPATH, COOKIE_DOMAIN, false, true);

There are multiple alternative but for it work perfectly on multiple installation.

Regular Expression Rules in Form Validation for Ext.CodeIgniter

logoYes, I have a problem with CodeIgniter built-in Form Validation Library, the lack of direct Regular Expression test/rule is a huge turn off for me especially when I need to use Regular Expression to as a rule to verify user input.

There are alternative with the use of “callback” to by creating an additional method inside your Controller. The solution is good if you have a complex filtering but why bother when all you need to do is a simple RegExp verification. Based on my Twitter status:

[Click here to read more...]

CRUD Library for Ext.CodeIgniter: An Example

logoOne of the drawback on CodeIgniter is the Scaffolding Class which is only suitable for testing or development stage. In order to do the same functionality you might find in other PHP Framework for CRUD you have to combine few available libraries in CodeIgniter including Table, Pagination, Form Validation and etc. All the libraries are great but you will end up having to write a long list of function and code to do still CRUD process.

To make the learning process much easier to understand I would actually try to convert CodeIgniter From Scratch: Day 5 – CRUD from Nettuts+ from using available libraries to Ext.CodeIgniter CRUD Library.

Requirements and Basic Informations

  • is based and developed on CodeIgniter 1.7.1, it might work with previous version but please do test it out first.
  • requires Table, Pagination, Form (Ext.CodeIgniter Library), Form Validation libraries and Form helper.
  • callback can be optimized with Template Library for Ext.CodeIgniter.
  • your model code can be minimized with ActiveRecord, you may require more works if using raw SQL.

[Click here to read more...]

Convert Currency to The Nearest RM0.05

Malaysia recently introduce a rounding mechanism for trading to remove the need for 1 cent in the market, but with this new implementation it cause us web developer more task to make it work with our current application.

The Rounding Mechanism is a method whereby the total bill amount (including goods and services subject to tax) is rounded upwards or downwards to the nearest multiple of 5 sen. In this regard, total bill amount that ends in 1, 2, 6 and 7 sen will be rounded down while 3, 4, 8 and 9 sen will be rounded up to the nearest multiple of 5 sen.

For example, a total bill amounting to RM82.01 will be rounded down to RM82.00. If it amounts to RM82.04, it will be rounded up to RM82.05.

Source BNM Rounding Mechanism

[Click here to read more...]

Database Table Prefix in CodeIgniter

I must say one of the main reason why I started to look into ActiveRecord for CodeIgniter was the availability to use database table name prefix.

|    ['dbprefix'] You can add an optional prefix, which will be added
|                 to the table name when using the  Active Record class
$db['default']['dbprefix'] = "feed_";

For example: TABLE feed_item

$this->db->get('item');

Many might not know that you can also use it with normal database query using 'swap_pre'. In ./system/application/config/database.php

|    ['dbprefix'] You can add an optional prefix, which will be added
|                 to the table name when using the  Active Record class
$db['default']['dbprefix'] = "feed_";
$db['default']['swap_pre'] = "{PRE}";

So now you can actually use.

$sql = "SELECT * FROM {PRE}item";
$query = $this->db->query($sql);