Cakephp important facts you must know – Part 2

CakePHP comes with a bunch of useful helpers and components which provide user handy tools to process and manipulate data. These helpers are not only the valuable assets for the framework user, but can be of great help to someone writing a core php application and not using the CakePHP framework.

Here are a few examples:

Number Helper

Number helper provides useful function to manipulate numbers.


precision() returns a number formatted with a level of precision. For example:


This function takes filesize as a argument and return the well formatted string mentioning the size in terms of bytes, KB, MB, GB and TB. For example:

Other function in number helper are:
toPercentage(): Formats a number into a percentage string.
format():Formats a number into a currency format.
currency():Formats a number into a currency format labeled with currency sign.

See cake/libs/view/helpers/number.php for a complete list of number helper functions and their usage guidelines.


TextHelper provides useful function to manipulate text strings.


Highlights a given phrase in a text. You can specify any expression in the third argument that may include the \1 expression to include the $phrase(second argument) found in the $text(first argument). For example:

This is the string in which word example will be highlighted

Note: you must have to define a css style for “highlight” in your css stylesheet. for example:


Strips all links (< href=….) from given text. Example:


Adds links (<a href=….) to a given text, by finding text that begins with strings like http:// and ftp://.


Adds email links (<a href=”mailto:….) to a given text.


Cuts a string to the length of given second argument and replaces the last characters. Takes care of HTML tags and encoding.

For example:


Extracts an excerpt from the text surrounding the phrase with a number of characters on each side determined by radius.


Creates a comma separated list where the last two items are joined with ‘and’, forming natural English.

See cake/libs/view/helpers/text.php for a complete list of text helper functions and their usage guidelines.

Time Helper


Converts given time (in server’s time zone) to user’s local time, given his/her offset from GMT.


Returns a nicely formatted date string for given Datetime string.


Returns a formatted descriptive date string for given datetime string.


Returns true if given datetime string is today.


Returns true if given datetime string is within this week.


Returns true if given datetime string is within this month.


Returns true if given datetime string is within this month.


Returns true if given datetime string was yesterday.


Returns true if given datetime string is tomorrow.


Returns either a relative date or a formatted date depending on the difference between the current time and given datetime.


Returns a UNIX timestamp, given either a UNIX timestamp or a valid strtotime() date string.

See cake/libs/view/helpers/time.php for a complete list of time helper functions and their usage guidelines. Additionally, there are other helpers some of which are (for example html, form, javascript, ajax) the backbones of cakephp view section. One must look into them inside cake/libs/view/helpers for the best possible usage of them.

Ready made Auth Component

In CakePHP there are several systems for authenticating users, each of which provides different options. At its core the authentication component will check to see if a user has an account with a site. If they do, the component will give access to that user to the complete site.

This component can be combined with the ACL (access control lists) component to create more complex levels of access within a site. The ACL Component, for example, could allow you to grant one user access to public site areas, while granting another user access to protected administrative portions of the site.

CakePHP’s AuthComponent can be used to create such a system easily and quickly. More detailed information and “how to use” tutorial could be found on page.

Leave a Reply