Cakephpdocs 36

CategoryHTML helper functions - link
Code Exampleslink( title[string], url[mixed], attributes[array], confirmMessage[string], escapeTitle[bool] ) The first parameter in the HTML helper's link() function is the text to be displayed. The second parameter is the URL, following the application's routes, that will be placed in the link. example: link('

' . $post['Post'['name'] . '

', '/posts/view/' . $post['Post']['id'], null, null, false); ?> link('Add a Post','/posts/add');?> But you can use an alternate method for producing this same link by entering an array in the url parameter, like so: link('Add a Post',array('controller'=>'posts','action'=>'add'));?> Of course, entering an absolute URL into the url parameter will send the user off site: link('Check out the Bakery','http://bakery.cakephp.org');?> You can include a confirmation message to be displayed as a JavaScript alert dialog box by entering a string in the confirmMessage parameter. For instance, say you wanted to alert the user before deleting records from the database. You could do this by entering the confirm message in the $html->link() function: link('Delete','/posts/delete/'.$post['Post']['id'],null,'Are you sure you want to delete this post?');?> When this is clicked, a box will appear asking the user "Are you sure you want to delete this post?" If the user clicks Proceed, then the link will be activated. You can include HTML tags in this function by setting the escapeTitle parameter to false. Even other helper functions that output HTML can be included in the title parameter, like so: link($html->image('title.jpg'),'/',null,null,false);?>
Test Code
Links
Remarks
Cancel