Upgrading from Previous Versions

Contributing To Bonfire

Modules

Bonfire provides a number of resources that are loaded globally and are intended to make life a little easier for you. Most of these are loaded from the application/helpers/application_helper.php file.

$current_user

If a user is logged in, you can access the current user's detail within any of your controllers that extend Bonfire's provided controllers, like Front_Controller, Admin_Controller, etc. This is accessed by $this->current_user.

The exact details may change over the versions, but the entire users table record is provided to you.

This same data is made available within all of your views as $current_user.

<?php echo $current_user->display_name ?>

e()

A convenience function that can (and probably should) be used to replace echo() in any places that you output text that a user might have entered. This function helps to defeat XSS attacks by running the text through htmlspecialchars().

<?php e($user->display_name); ?>

js_escape()

Performs some simple escaping of strings that will be inserted into javascript functions, like confirm() or alert(). Not suitable for use by itself within document.write. The only parameter is the string to escape.

dump()

Outputs the given variables with formatting and location. Any number of parameters can be passed to this function and they will all be printed out in a helpful manner, but script execution will continue.

gravatar_link()

Returns a URL for the user from Gravatar and provides a default image (the identicon) when the user hasn't provided one. This is intended to be used within your views for displaying the user's avatar.

The first parameter is the email address for the user. This is how they are referenced at Gravatar. The second parameter is the size of the image in pixels. The third parameter is the alt tag and the fourth parameter is the title for the tag. The fifth and sixth parameters are the class and id to be given to the img, respectively.

logit()

Logs an error to the Console in the profiler (if loaded) and to the log files.

logit('Some debugging message', 'debug');

The first parameter is the message to log. The second parameter is the log level.

If the profiler is enabled and the Console class is loaded, which it is by default in development mode, the string will show up in the Console section of the profiler.

If logging is enabled in your application/config/config.php file, then it will also be logged to your default log file.

module_folders()

Returns an array of the folders that modules are allowed to be stored in. These are set in application/config/config.php.

module_list

Returns a list of all modules in the system. If TRUE is passed as the only parameter, any Bonfire core modules will NOT be shown, only your custom modules. If FALSE is passed, both core and custom modules will be listed.

module_controller_exists()

Looks within a module to see if a certain controller exists. The first parameter is the name of the controller, and the second parameter is the module name.

It returns either TRUE or FALSE.

if (module_controller_exists('content', 'users')) { . . . }

module_file_path()

Locates a file within a module and returns the path to that file. The first parameter is the name of the module. The second parameter is the name of the folder. The last parameter is the name of the file that you're looking for (including the extension).

It returns the full server path to the file, if found.

$path = module_file_path('users', 'assets', 'js/users.js');

module_path()

Returns the full server path to a module and, optionally, a folder within that module. The first parameter is the name of the module. The second parameter is the name of the folder.

$path = module_path('users', 'assets');

module_files()

Returns an associative array of files within one or more modules.

The first parameter is the name of the module to restrict the search to. If left NULL, this will provide a list of all files within all of the modules. If a module name is specified, the search will be restricted to that module's files only.