What Are Helpers?
Helpers are PHP files with little (or big) snippets of code that you can use anywhere in your Dingo application. Helpers behave exactly like Views, but generally contain PHP code rather than HTML, CSS, or JavaScript.
Create A Helper
Create a new PHP file at application/helpers/hello.php. This will be your helper. All helpers in Dingo are located in the application/helpers folder. Now put the following content into your helper:
<?php echo "Hello, World!";
You can now use this helper in your controllers, views, and models like so:
load::helper('hello');
The above would display "Hello, World!".
Auto Loading Helpers
If you are going to use a particular helper a lot, then you should consider auto loading it by adding it to the autoload_helpers array in /application/config/development/config.php. For example, you could auto load your new helper by editing config.php like so:
/* Auto Load Helpers */
config::set('autoload_helpers',array('hello'));
It is also possible to load helpers on a controller-by-controller basis by adding the $autoload_helpers array to the controller class.
class main_controller
{
public $autoload_helpers = array('hello');
// ...
}
© 2008 - 2010 Evan Byrne