CakePHP Global Constants and Functions CakePHP Global Constants and Functions

If you ever find yourself perusing some of the default code that comes with CakePHP, you might find yourself somewhat curious and confused when you see such functions as <?php e('Hello World');?> or <?pho echo h('<a href="">Hello World</a>');?>.

I know I certainly was and became determined to understand what the heck these were doing.  It quickly became apparent that these were just two of the many built-in extension functions that are part of the CakePHP framework!

 These two functions are probably the most common functions; the e function is a short cut for the echo function.  Meanwhile the h function is another short cut, but this time for the htmlspecialshars function.  I'm sure the amount of time the framework developers had to type htmlspecialchars they quickly decided to build a full set of these functions!

Starting of the alphabetically list of global functions are a variety of functions related to localization.  The first being the double underscore (__).  This is followed by several other localization functions that help customize specific actions, e.g. select from a specific category or domain.

Similar to the e function, there are two similar functions for outputting data.  debug() allows you to output a debug message that will display the file and line number; useful for understanding the order of executed code.  There is also a pr function that implements the print_r() function.

Next there are several functions for dealing arrays, environment variables, stripping slashes, checking if files exist, etc…

Along with these useful functions, there are also several useful constants that are defined that contain useful file path information as well as several more constants relating to timing values.  E.g. the number of seconds in an hour or year, etc…

If you are interested in seeing the full list as well as the full descriptions navigate over to the CakePHP Cookbook:

This link is explicitly for CakePHP 2.x; however, you can quickly find links for older versions as well.

Published on Sep 21, 2012

Tags: CakePHP Tutorial | php

Related Posts

Did you enjoy this article? If you did here are some more articles that I thought you will enjoy as they are very similar to the article that you just finished reading.


Learn how to code in HTML, CSS, JavaScript, Python, Ruby, PHP, Java, C#, SQL, and more.

No matter the programming language you're looking to learn, I've hopefully compiled an incredible set of tutorials for you to learn; whether you are beginner or an expert, there is something for everyone to learn. Each topic I go in-depth and provide many examples throughout. I can't wait for you to dig in and improve your skillset with any of the tutorials below.