Fuel Documentation

Fuel Class

The Fuel class contains the core methods of the FuelPHP framework. The public methods in this class that can be used in your application are documented here. All other methods are for internal use only, and should not be used.

Class constants

Environment constants. These are used in your config.php to define the application environment:

Name Type Value Description
TEST string
'test'
Identifies the TEST environment.
DEVELOPMENT string
'dev'
Identifies the DEVELOPMENT environment.
QA string
'qa'
Identifies the QA environment.
PRODUCTION string
'production'
Identifies the PRODUCTION environment.

Logging constants. These are used by the Log class, and by the base function logger():

Name Type Value Description
L_NONE integer
0
Logging level 0: do not log.
L_ERROR integer
1
Indicates an error message is logged.
L_DEBUG integer
2
Indicates a debug message is logged.
L_INFO integer
3
Indicates an informational message is logged.
L_ALL integer
4
All logging levels.

Other constants:

Name Type Value Description
VERSION string
'1.0.0-dev'
Version of the current FuelPHP installation.

Class properties

To be written.

find_file($directory, $file, $ext = '.php', $multiple = false, $cache = true)

The find_file method is used to locate files in a FuelPHP application directory structure.

The method searches through all search paths defined in the active Request instance, the application path, all loaded package paths and the core path (in this order). You can also use the method 'add_path' to manually add global search paths.

Static Yes
Parameters
Param Default Description
$directory required Relative directory name in which you want to search for files.
$file required Name of the file you want to find.
$ext
'.php'
Extension of the file you're looking for. Note the leading dot, which is required!
$multiple
false
If false, the first file found is returned. If true, an array of all files found that match the criteria is returned.
$cache
true
If true, the result will be cached for subsequent requests. If false, the result will not be cached.
Returns Mixed, either string or an array of strings.
Example
// find all views named 'test'
$views = Fuel::find_file('views', 'test', '.php', true);

list_files($directory = null, $filter = '*.php')

The list_files method gets a list of all the files in a given directory inside all of the loaded search paths (e.g. the cascading file system). This is useful for things like finding all the config files in all the search paths.

Static Yes
Parameters
Param Default Description
$directory required Relative directory name in which you want to search for files.
$filter
'*.php'
Filename filter, to be used in the search.
Returns Array
Example
// find all config files in this FuelPHP installation
$files = Fuel::list_files('config');

add_path($path, $prefix = false)

The add_path method allows you to add a global search path. The search paths are used by Fuel::find_file() to locate files within your application.

Static Yes
Parameters
Param Default Description
$path required Path to be added to the list of global search paths
$prefix
false
If false, the path will be added to the search path, just after APPPATH. If true, it will be prepended to the list.
Returns void
Example
// prepend the applications myfiles folder to the global search path
Fuel::add_path(APPPATH.'myfiles'.DS, true);

get_paths()

The get_paths method returns the defined list of search paths.

Static Yes
Parameters No
Returns void
Example
// get the defined search paths
$paths = Fuel::get_paths();

load($file)

The load method loads (includes) a given file, and returns the results. This method is used for example to load configuration files, which return an array of configuration settings.

Static Yes
Parameters
Param Default Description
$file required Filename of the file to be loaded
Returns Mixed
Example
// load a PHP file
if (Fuel::load('myfile.php'))
{
	echo "MyFile was loaded successfully";
}

Note that if the included file does NOT contain a return statement, load() will return 1 if the load was successful, or 0 if the file could not be loaded!

add_package($package)

The add_package method allows you to add one or more packages at runtime.

Static Yes
Parameters
Param Default Description
$package required Name of the package to be loaded, or an array of packages and package paths.
Returns void
Example
// load the ORM package
Fuel::add_package('ORM');

// add multiple packages from a single package installation
Fuel::add_package( array('First' => PKGPATH.'my'.DS.'first'.DS, 'Last' => PKGPATH.'my'.DS.'last'.DS) );

remove_package($package)

The add_package method allows you to remove a package at runtime.

Static Yes
Parameters
Param Default Description
$package required Name of the package to be removed.
Returns void
Example
// remove the ORM package
Fuel::remove_package('ORM');