Here are some globally available constants and functions that you
might find useful as you build your application with Cake.
Here are Cake's globally available functions. Many of them are
convenience wrappers for long-named PHP functions, but some of them (like
vendor() and uses()) can be used to include code, or perform other useful
functions. Chances are if you're wanting a nice little function to do
something annoying over and over, it's here.
Loads Cake's core configuration file. Returns true on
success.
string |
$lib1;
|
string |
$lib2...;
|
Used to load Cake's core libaries (found in
cake/libs/). Supply the name of the lib filename
without the '.php' extension.
uses('sanitize', 'security');
vendor(
|
$lib1, |
|
| |
$lib2...); |
|
string |
$lib1;
|
string |
$lib2...;
|
Used to load external libraries found in the /vendors directory.
Supply the name of the lib filename without the '.php' extension.
vendor('myWebService', 'nusoap');
debug(
|
$var, |
|
| |
$showHtml = false); |
|
mixed |
$var;
|
boolean |
$showHtml = false;
|
If the application's DEBUG level is non-zero, the $var is printed
out. If $showHTML is true, the data is rendered to be
browser-friendly.
Returns an array of the parameters used to call the wrapping
function.
function someFunction()
{
echo print_r(a('foo', 'bar'));
}
someFunction();
// output:
array(
[0] => 'foo',
[1] => 'bar'
)
Used to create associative arrays formed from the parameters used to
call the wrapping function.
echo aa('a','b');
// output:
array(
'a' => 'b'
)
Convenience wrapper for echo().
Convenience wrapper for strtolower().
Convenience wrapper for strtoupper().
r(
|
$search, |
|
| |
$replace, |
|
| |
$subject); |
|
string |
$search;
|
string |
$replace;
|
string |
$subject;
|
Convenience wrapper for str_replace().
Convenience function equivalent to:
echo "<pre>" . print_r($data) . "</pre>";
Only prints out information if DEBUG is non-zero.
am(
|
$array1, |
|
| |
$array2...); |
|
array |
$array1;
|
array |
$array2...;
|
Merges and returns the arrays supplied in the parameters.
Gets an environment variable from available sources. Used as a
backup if $_SERVER or $_ENV are disabled.
This function also emulates PHP_SELF and DOCUMENT_ROOT on
unsupporting servers. In fact, it's a good idea to always use env()
instead of $_SERVER or getenv() (especially if you plan to distribute the
code), since it's a full emulation wrapper.
cache(
|
$path, |
|
| |
$expires, |
|
| |
$target = 'cache'); |
|
string |
$path;
|
string |
$expires;
|
string |
$target = 'cache';
|
Writes the data in $data to the path in /app/tmp specified by $path
as a cache. The expiration time specified by $expires must be a valid
strtotime() string. The $target of the cached data can either be 'cache'
or 'public'.
clearCache(
|
$search, |
|
| |
$path = 'views', |
|
| |
$ext); |
|
string |
$search;
|
string |
$path = 'views';
|
string |
$ext;
|
Used to delete files in the cache directories, or clear contents of
cache directories.
If $search is a string, matching cache directory or file names will
be removed from the cache. The $search parameter can also be passed as an
array of names of files/directories to be cleared. If empty, all files in
/app/tmp/cache/views will be cleared.
The $path parameter can be used to specify which directory inside of
/tmp/cache is to be cleared. Defaults to 'views'.
The $ext param is used to specify files with a certain file
extention you wish to clear.
stripslashes_deep(
|
$array); |
|
Recursively strips slashes from all values in an array.
Returns the number of dimensions in the supplied array.
fileExistsInPath(
|
$file); |
|
Searches the current include path for a given filename. Returns the
path to that file if found, false if not found.
Converts forward slashes to underscores and removes first and last
underscores in a string.