It is encouraged that you follow Kohana's coding style. This makes code more readable and allows for easier code sharing and contributing.
Class names in Kohana follow a strict convention to facilitate autoloading. Class names should have uppercase first letters with underscores to separate words. Underscores are significant as they directly reflect the file location in the filesystem.
The following conventions apply:
classes
directory. This may be at any level in the cascading filesystem.Remember that in a class, an underscore means a new directory. Consider the following examples:
Class Name | File Path |
---|---|
Controller_Template | classes/Controller/Template.php |
Model_User | classes/Model/User.php |
Model_BlogPost | classes/Model/BlogPost.php |
Database | classes/Database.php |
Database_Query | classes/Database/Query.php |
Form | classes/Form.php |
In order to produce highly consistent source code, we ask that everyone follow the PSR-12 coding standard except the naming conventions below.
Kohana uses under_score naming, not camelCase naming.
// Controller class, uses Controller_ prefix
class Controller_Apple extends Controller
{
}
// Model class, uses Model_ prefix
class Model_Cheese extends Model
{
}
// Regular class
class Peanut
{
}
Kohana follows the PSR-5 PHPDoc standard.