Classes
What is a class?
A class is just a normal PHP class. It doesn't need to extend anything or follow any conventions other than the naming convention which is the same as all other classes in Fuel.
class Session
That will be loaded from app/classes/session.php.
Loading Classes
Unlike some other frameworks classes do not need to be loaded manually. They will be auto-loaded when you refer to them in your code (Controllers, Models, etc).
Classes in a sub-directory
Just like Controllers, classes must be lower-case with first-letter upper case, while underscores will put the class into a sub-directory.
Class Session_Driver
That will be loaded from app/classes/session/driver.php
Initializing your class
It is possible to have Fuel's autoloader perform certain automated tasks once a class is loaded,
sort of like what __construct()
does for instances of a class. You do this by adding
a public static _init()
method to the class.
class Example {
public static function _init()
{
// this is called upon loading the class
}
}
If a loaded class has its own _init()
method and a parent must be loaded
alongside it, that parent's init method isn't called unless you call it using
parent::_init();