CakePHP docs
| Id/Actions | Category | Code Examples | Links | Remarks |
|---|---|---|---|---|
| 79 View |
8 Built-in Components | AclComponent AuthComponent CookieComponent EmailComponent PaginatorComponent RequestHandlerComponent SecurityComponent SessionComponent |
||
| 78 View |
magic functions | Values entered in the place of magic variable slots in the URL are passed to the action through the $this->params array. In the previous example, the given month would be available in the array as this: $this->params['month'] and so forth. The $this->params array may be checked or called in the controller and the view. The available magic functions include the following: • $Action • $Day • $Month • $Year • $ID |
||
| 77 View |
The XML Helper | This helper can streamline some typical XML processes.
To include this helper in the application, use this:
var $helpers = array('Xml');
Table: XML Helper Functions
Function Description
===== =================================
$xml->elem() Creates an XML element
$xml->header() Generates an XML document header
$xml->serialize() Converts a model result set, or a Cake-formatted array, into XML |
||
| 76 View |
The Time Helper | Some common date-time methods are easier to manage. From SQL
query string handling to rendering nicely formatted dates, this helper is
useful for any Cake application that relies on time elements.
To include this helper in the application, use this:
var $helpers = array('Time');
Table: Time Helper Functions
Function Description
===== ===============================
$time->dayAsSql() Returns a partial SQL string to search for records
between two times occurring on the same day
$time->daysAsSql() Returns a partial SQL string to search for records between two dates
$time->format() Returns a formatted date string; converts valid
strtotime() strings or Unix timestamps
$time->fromString() Returns a Unix timestamp from a given valid
strtotime() string or integer
$time->gmt() Converts a given Unix timestamp or valid strtotime()
string to Greenwich mean time
$time->isThisMonth() Returns true if given datetime string is within this month
$time->isThisWeek() Returns true if given datetime string is within this week
$time->isThisYear() Returns true if given datetime string is within this year
$time->isToday() Returns true if given datetime string is today
$time->isTomorrow() Returns true if given datetime string is tomorrow
$time->nice() Formats a datetime string into a readable string
$time->niceShort() Like nice(), except it condenses the string to less words and digits
$time->relativeTime() Alias for timeAgoInWords(); can also calculate future dates
$time->timeAgoInWords() Compares the difference between a given
datetime string and the current time; expresses the difference in past
terms (for example, three days ago)
$time->toAtom() Formats date strings to be used in Atom feeds
$time->toQuarter() Returns the quarter for a given date
$time->toRSS() Formats date strings to be used in RSS feeds
$time->toUnix() Convenience wrapper for the strtotime() function
$time->wasWithinLast() Returns true if the given date is within the given interval
$time->wasYesterday() Returns true if given datetime string represents yesterday |
||
| 75 View |
The Text Helper | When dealing with text, tasks such as truncating and highlighting can
require complicated regular expressions or tedious PHP operations. The
Text helper condenses some of these common web text methods into
helper functions.
To include this helper in the application, use this:
var $helpers = array('Text');
Table: Text Helper Functions
Function Description
===== ==========================
$text->autoLink() Converts all links and e-mail addresses into HTML links
$text->autoLinkEmails() Provides an e-mail link for given text
$text->autoLinkUrls() Finds text beginning with http:// or ftp:// and
wraps a link tag around it
$text->excerpt() Extracts an excerpt of text by a given phrase
$text->highlight() Highlights a given string of text
$text->stripLinks() Removes links from text
$text->toList() Formats an array as a comma-separated, readable list
$text->trim() Alias for truncate()
$text->truncate() Truncates text to a given length |
||
| 74 View |
The Session Helper | The Session helper displays session information as provided by its
component and controller. It displays flash messages, errors, and
reading session data with convenience functions listed
in the following Table.
To include this helper in the application, use this:
var $helpers = array('Session');
Table: Session Helper Functions
Function Description
===== ==============================
$session->activate() Turns on session handling if the app/config/core.php file's
Session.start attribute is set to false
$session->check() Returns true if a session key is set
$session->error() Returns the last error encountered in the session
$session->flash() Renders messages set with the Session component setFlash() function
$session->id() Returns the session ID
$session->read() Returns all values stored in a given session key
$session->valid() Returns whether a session key is available in the view
$session->write() Overrides the Session component write() function;
should not be used in a view but may be called in other helper functions |
||
| 73 View |
The RSS Helper | The RSS helper creates standards-compliant RSS feeds.
To include this helper in the application, use the following:
var $helpers = array('Rss');
Table: RSS Helper Functions
Function Description
===== ============================
$rss->channel() Returns the <channel> element
$rss->document() Returns an RSS document contained in <rss> tags
$rss->item() Converts an array to an RSS element
$rss->items() Converts an array of data using an optional
callback; maps the array to a set of RSS tags
$rss->time() Converts a specified time stamp in any format to an RSS time specification |
||
| 72 View |
The Paginator Helper | This helper works together with the Pagination component to
break up data into multiple pages or to sort data by specified
parameters.
To include this helper in the application, use the following:
var $helpers = array('Paginator');
Table: Paginator Helper Functions
Function Description
===== =========================
$paginator->counter() Returns a counter string for the current paginated results set
$paginator->current() Returns the current page of the paginated results set
$paginator->defaultModel() Returns the default model of the paginated sets
$paginator->first() Returns the first or set of numbers for the
first pages of paginated results
$paginator->hasNext() Returns true if the supplied result set is
not the last page of paginated results
$paginator->hasPage() Checks whether a given page number
has a result set in paginated results
$paginator->hasPrev() Returns true if the supplied result set is
not the first page of paginated results
$paginator->last() Returns the last or set of numbers for the last
pages of paginated results
$paginator->link() Creates a link with pagination parameters
$paginator->next() Creates a link to the next set of paginated results
$paginator->numbers() Returns a set of numbers on each side
of the current page for more direct access to other results
$paginator->options() Sets default options for all pagination links
$paginator->params() Returns the current page of the results set for a given model
$paginator->prev() Creates a link to the previous set of paginated results
$paginator->sort() Creates a sorting link for a column in the results set
$paginator->sortDir() Returns the direction by which the given results set is ordered
$paginator->sortKey() Returns the key by which the given results set is ordered
$paginator->url() Creates a pagination URL to access other pages of the results set |
||
| 71 View |
The Number Helper | This is a simple helper for dealing with number formats.
To include this helper in the application, use this:
var $helpers = array('Number');
Table: Number Helper Functions
Function Description
===== =============================
$number->currency() Formats a floating-point integer into a currency format
$number->format() Formats a floating-point integer according to provided settings
$number->precision() Formats the number based on the specified precision value
$number->toPercentage() Makes a number a percentage
$number->toReadableSize() Returns a number of bytes into a readable size format (for example, KB or MB) |
||
| 70 View |
The JavaScript Helper | This helper is used mainly to simplify coding JavaScript.
To include this helper in the application, use this in controller (or app_controller globally):
var $helpers = array('Javascript');
Functions in the JavaScript Helper
Function Description
========= ===========================
$javascript->afterRender() Callback for after rendering; writes
cached events to the view or a temp file
$javascript->blockEnd() Ends a block of JavaScript code
$javascript->cacheEvents() Caches JavaScript events created with the event() function
$javascript->codeBlock() Wraps JavaScript code with the <script> tag
$javascript->escapeScript() Escapes carriage returns and single
or double quotes for JavaScript code segments
$javascript->escapeString() Escapes strings to be JavaScript compatible
$javascript->event() Used with the Prototype framework to
attach an event to an element
$javascript->getCache() Gets the current JavaScript cache; also clears JavaScript caches
$javascript->includeScript() Includes a script inside a single <script> tag
$javascript->link() Links to JavaScript files for use in a web page
$javascript->object() Creates a JSON object from an array
$javascript->writeEvents() Writes cached JavaScript events |
||
| 69 View |
Ajax helpers | Not only can the Ajax helper simplify using Prototype, but it can also make animation effects easier to use. |
||
| 68 View |
form helpers - Form Input Element Functions | Table: Form Input Element Functions Function Name and Parameters =================================== button( title[string], options[array] ) checkbox( field[string], options[array] ) file( field[string], options[array] ) hidden( field[string], options[array] ) password( field[string], options[array] ) radio( field[string], options[array], attributes[array] ) submit( caption[string], options[array] ) select( field[string], options[array], selected[mixed], attributes[array], showEmpty[mixed] ) text( field[string], options[array] ) textarea( field[string], options[array] ) dateTime( field[string], dateFormat[string], timeFormat[string], selected[string], attributes[array], showEmpty[mixed] ) day( field[string], selected[string], attributes[array], showEmpty[mixed] ) month( field[string], selected[string], attributes[array], showEmpty[mixed] ) year( field[string], minYear[int], maxYear[int], selected[string], attributes[array], showEmpty[mixed] ) hour( field[string], format[bool], selected[string], attributes[array], showEmpty[mixed] ) minute( field[string], selected[string], attributes[array], showEmpty[mixed] ) meridian( field[string], selected[string], attributes[array], showEmpty[mixed] ) error( field[string], message[string], options[array] ) |
||
| 67 View |
form helpers - label | This function renders a <label> element and wraps it around a specified input field. The $form->input() function automatically runs this function when rendering input fields (which can be suppressed in that function’s options). label( field[string], text[string], attributes[array] ) |
||
| 66 View |
form helpers - secure | To prevent cross-site request forgery (CSRF) attacks, many
developers use the hash insertion technique. In short, the
$form->secure() function facilitates hash insertions by generating
a hidden form field containing a hash based on other fields in the
form.
secure( fields[array] )
<?=$form->secure(array('Post'=>array('id','name'));?>
This will output the hidden input element with a server-side-
generated hash:
<fieldset style="display:none;">
<input type="hidden" name="data[_Token][fields]"
value="1932368593ef664fc975581e92e2df1490401570"
id="TokenFields1314770757" />
</fieldset>
The value of the hidden input element will certainly change
depending on the Security.salt value set in the app/config/core.php
file and the function’s own randomization algorithm. This hash is
accessible in the $this->data array under the ['_Token']['fields] key. |
||
| 65 View |
form helpers - end | end
However, the $form->end() function can conveniently combine
into one string the submit button, which is typically the last form
element displayed and the closing </form> tag.
end( options[mixed] )
<?=$form->end(array('label'=>'Submit Form','id'=>'submit_btn'));?>
This line will return the following output:
<input type="submit" value="Submit Form" id="submit_btn" />
</form> |
Page 1 of 6, showing 15 records out of 79 total, starting on record 1, ending on 15
