3.10.1 Using Helpers
You use helpers in CakePHP by making a controller aware of them. Each controller has a $helpers property that lists the helpers to be made available in the view. To enable a helper in your view, add the name of the helper to the controller’s $helpers array.
<?php
class BakeriesController extends AppController {
var $helpers = array('Form', 'Html', 'Javascript', 'Time');
}
?>
<?phpclass BakeriesController extends AppController {var $helpers = array('Form', 'Html', 'Javascript', 'Time');}?>
You can also add helpers from within an action, so they will only be available to that action and not the other actions in the controller. This saves processing power for the other actions that do not use the helper as well as help keep the controller better organized.
<?php
class BakeriesController extends AppController {
function bake {
$this->helpers[] = 'Time';
}
function mix {
// The Time helper is not loaded here and thus not available
}
}
?>
<?phpclass BakeriesController extends AppController {function bake {$this->helpers[] = 'Time';}function mix {// The Time helper is not loaded here and thus not available}}?>
See comments for this section
