CakePHP comes with a bunch of useful helpers and components that provide convenient tools for processing and manipulating data. These helpers are significant not only for the framework user, but can also be of great help to someone who writes PHP applications without using CakePHP.
Here are some examples:
Numberhelper
Number helper contains powerful functions for manipulating numbers.
')
precision ()precision () returns a number formatted with a precision level. For example:
echo $ number-> precision (25.02558, 3);
// displays
25.026
toReadableSize ()This function takes the file size as an argument and returns a well-formatted string indicating the size in bytes, Kb, Mb, GB and TB. For example:
echo $ number-> toReadableSize (2502558);
// displays
2.39 MB
Other Numer helper functions:
toPercentage () : Formats a number in percentages.
format () : Formats a number in a monetary format.
currency () : Formats a number in a currency format signed by a currency sign.
See the file
cake / libs / view / helpers / number.php for a complete list of Number
Helper functions and their uses.
Texthelper
Text helper contains useful functions for manipulating text strings.
highlight ()Highlights the specified phrase in the text. For example:
echo $ text-> highlight ("Word example will be highlighted", "example");
// displays
Will be highlighted
* (example will be highlighted. Habr does not allow it to show)
Note: you must define a style for the “highlight” class in your CSS. For example:
.highlight {background: # FFFF00;}
stripLinks ()Removes all links (<a href = ....) From the given text. Example:
echo $ text-> stripLinks ('Dont show the clickable link on <a href="http://www.givebackindia.com"> Online Charity Mall </a>');
// displays
Dont show the clickable link on Online Charity Mall
autoLinkUrls ()Adds links (<a href = ....) In specified text in which strings begin with http: // and.
autoLinkEmails ()Adds email links (<a href = ”mailto: ....) In the specified text.
truncate ()Cuts the string to the length specified in the second parameter and replaces the last characters. Takes care of HTML tags and encoding.
For example:
echo $ text-> truncate ("), 50);
// outputs
Cuts a string of the second arg ...
excerpt ()Creates an excerpt from the text around the search phrase with a length of a certain radius and adds an ending.
toList ()Creates a comma separated list where the last two elements are joined by 'and'.
See the file
cake / libs / view / helpers / text.php for a complete list of functions and their use.
Time helper
convert ()Converts the given time (in the server's time zone) to the user local time with a shift from GMT.
nice ()Returns a well-formatted string for a given datetime string.
niceShort ()Returns a formatted date string as a description.
isToday ()Returns true if the given datetime string is equal to the current date.
isThisWeek ()Returns true if this date is current week.
isThisMonth ()Returns true if the given date is in the current month.
isThisYear ()Returns true if the given date is in the current year.
wasYesterday ()Returns true if the given date was yesterday.
isTomorrow ()Returns true if the given date is tomorrow.
timeAgoInWords ()Returns relative date or formatted depending on the difference between the current date and the given.
format ()Returns the UNIX timestamp given in either the UNIX timestamp or the correct strtotime () string.
See the file
cake / libs / view / helpers / time.php for a complete list of functions and their use.
There are also other helpers, some of them (for example html, form, javascript, ajax) the frame mappings in CakePHP. You need to look at them in
cake / libs / view / helpers for better use.