Cakephpdocs

No Category Code Examples Test Code Links Remarks
 51 Functions in the Ajax Helper (18 of them) - use Prototype JavaScript Framework Function Description ===== ========================== afterRender() Includes code blocks after a view has been rendered autoComplete() Creates an autocomplete text field div() Creates a
element for Ajax updates divEnd() Closes an Ajaxed
element drag() Creates a draggable element; requires the Scriptaculous animation libraries drop() Creates a droppable element; requires Scriptaculous dropRemote() Creates an area that triggers an Ajax response when a draggable is dropped onto it editor() Creates an editor control that is swapped for the element when triggered by the user; requires Scriptaculous form() Creates a form element that runs in the background when submitted isAjax() Returns true if the current request is a Prototype update link() Creates a link to run an Ajax call observeField() Triggers an Ajax response when the observed field is changed observeForm() Observes a form and triggers an Ajax response when changed remoteFunction() Creates Ajax functions to be run, usually in conjunction with a link() event remoteTimer() Triggers an Ajax response at a specified time interval slider() Creates a slider control; requires Scriptaculous sortable() Makes lists or other objects sortable; requires Scriptaculous submit() Renders a form submit button that triggers an Ajax form submission
 52 HTML helper functions - charset charset( charset[string] ) charset = null: The character set to be used in the tag For example, the following: charset('UTF-16');?> will output this: => The default character set can be specified in the app/config/core.php file. Change the App.encoding setting on or near line 47 following the standard HTML character set specifications. (For your information, a list of registered character set values is available from the World Wide Web Consortium at www.w3.org/International/O-charset-lang.html.) The App.encoding value is originally set to UTF-8.
 53 HTML helper functions - css css( path[mixed], rel[string], attributes[array], inline[bool] ) css('cake.generic.print',null,array('media'=>'print'));?> or like so: css('cake.generic.screen',null,array('media'=>'screen'));?> Multiple style sheets can be called by passing an array in the path parameter: css(array('reset','type','layout'));?>
 54 HTML helper functions - div div( class[string], text[string], attributes[array], escape[bool] ) div('tab','Home');?> to output the following:
Home
div('story',$story['Story']['contents']);?> uses a few less characters than does this:
 55 HTML helper functions - docType docType( type[string] ) docType('xhtml-strict');?> the document type declaration is produced as the following string:
 56 HTML helper functions - image image( path[string], attributes[array] ) image('title.jpg',array('alt'=>'My Homepage','class'=>'title');?> outputs the following: My Homepage
 57 HTML helper functions - meta meta( type[string], url[mixed], attributes[array], inline[bool] ) $html->meta() outputs tags, which can be used for specifying a site description or other tags. It can also output tags for RSS feeds and a site favicon. meta('icon');?> returns these strings:
 58 HTML helper functions - nestedList nestedList( list[array], attributes[array], itemAttributes[array], tag[string] ) $posts = array( 'Post 1'=>array( 'Jan 1, 2008', 'No Author'), 'Post 2'=>array( 'Jan 2, 2008', 'Administrator') ); By placing this array in the list parameter of the $html->nestedList() function, the following HTML would be returned:
  • Post 1
    • Jan 1, 2008
    • No Author
  • Post 2
    • Jan 2, 2008
    • Administrator
 59 HTML helper functions - para para Simply put, this is a convenience function for wrapping the paragraph tag around a chunk of text. It can be useful in simplifying HTML escaping for content that may contain nonalphanumeric characters. para( class[string], text[string], attributes[array], escape[bool] ) para(null,'This is a test for the $html->para() function',null,true);?> will return the following when run through the $html->para() function:

This is a test for the $html->para() function

 60 HTML helper functions - style style( data[array], inline[bool] ) $styles = array( 'p_bold'=>array( 'font-size'=>'1.0 em', 'font-weight'=>'bold' ) 'p_italic'=>array( 'font-style'=>'italic' ) ); para(null,'Paragraph Text',array('style'=>$html->styles($stylesÃ¥ ['p_bold'])));?> This line would return the following HTML:

Paragraph Text

 61 HTML helper functions - tableHeaders tableHeaders( names[array], trAttributes[array], thAttributes[array] ) tableHeaders(array('1','2'),array('class'=>'row'),array('class'=>Ã¥ 'header'));?> will return the following:
1 2
 62 HTML helper functions - tableCells tableCells( data[array], oddTrAttributes[array], evenTrAttributes[array], useCount[bool] ) $html->tableCells() function: $cells = array( 'row1'=>array( 'column1','column2','column3' ), 'row2'=>array( 'column1','column2','column3' ) ); The actual text contained in the row keys (for example, row1 and row2) will not be displayed in the HTML output:
column1 column2 column3
column1 column2 column3
 63 HTML helper functions - addCrumb and getCrumbs $html->addCrumb() and $html->getCrumbs functions render breadcrumbs (for example, home->about->mailing address). addCrumb( name[string], link[mixed], attributes[array] ) getCrumbs( separator[string], startText[string] )
 64 form helpers - submit submit('Submit',array('onSubmit'=>'return false;'));?> will return a submit button containing the onSubmit attribute, like so:
 65 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 tag. end( options[mixed] ) end(array('label'=>'Submit Form','id'=>'submit_btn'));?> This line will return the following output:
 66 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] ) secure(array('Post'=>array('id','name'));?> This will output the hidden input element with a server-side- generated hash:
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.
 67 form helpers - label This function renders a
 68 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] )
 69 Ajax helpers Not only can the Ajax helper simplify using Prototype, but it can also make animation effects easier to use.
 70 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