Welcome to the Cookbook

loading...

3.11.2.1 Including other Helpers

You may wish to use some functionality already existing in another helper. To do so, you can specify helpers you wish to use with a $helpers array, formatted just as you would in a controller.

<?php
/* /app/views/helpers/link.php (using other helpers) */
class LinkHelper extends AppHelper {
    var $helpers = array('Html');

    function makeEdit($title, $url) {
        // Use the HTML helper to output
        // formatted data:

        $link = $this->Html->link($title, $url, array('class' => 'edit'));

        return $this->output("<div class=\"editOuter\">$link</div>");
    }
}
?>
  1. <?php
  2. /* /app/views/helpers/link.php (using other helpers) */
  3. class LinkHelper extends AppHelper {
  4. var $helpers = array('Html');
  5. function makeEdit($title, $url) {
  6. // Use the HTML helper to output
  7. // formatted data:
  8. $link = $this->Html->link($title, $url, array('class' => 'edit'));
  9. return $this->output("<div class=\"editOuter\">$link</div>");
  10. }
  11. }
  12. ?>