Helpers - adampatterson/Dingo-Framework GitHub Wiki
###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.
Note: It is highly recommended that you use models instead of helpers whenever possible. However, if you need to use a helper to include a class or something that won't work in a model, it is perfectly fine to use a helper.
###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');
// ...
}