Catalog / FuelPHP Cheatsheet
FuelPHP Cheatsheet
A quick reference guide for FuelPHP, a simple, flexible, community driven PHP 5.3+ framework, based on best practices and loaded with powerful features.
Core Concepts & Configuration
Key Concepts
HMVC (Hierarchical Model-View-Controller): FuelPHP extends the traditional MVC pattern to HMVC, promoting modularity and reusability of code. ORM (Object-Relational Mapper): Provides an ActiveRecord implementation for easy database interaction. |
Security: Built-in CSRF protection, input filtering, and output encoding to prevent common web vulnerabilities. Bundles: Reusable packages of code that can be easily integrated into FuelPHP applications. |
Modules: Self-contained applications within a FuelPHP project, enabling code organization and separation of concerns. |
Configuration Files
|
Main application configuration file. Located in |
|
Defines URL routes. Located in |
|
Database connection settings. Located in |
|
Specifies classes and packages to automatically load. Located in |
Environment Configuration
FuelPHP supports environment-specific configurations (development, production, testing).
|
Controllers, Models & Views
Controllers
Controllers handle user requests and interact with models to retrieve or modify data. |
Example:
|
Models
Models represent data and provide methods for interacting with the database. |
Example:
|
Views
Views are responsible for rendering data provided by controllers into HTML or other formats. |
Example (
|
Use |
Routing & URI Handling
Basic Routing
Routes define how URLs are mapped to controllers and actions. Defined in |
Example:
|
Named Parameters
You can use named parameters in your routes.
|
URI Class
|
Returns the base URL of the application. |
|
Returns the current URI. |
|
Returns the nth segment of the URI. |
ORM & Database
Basic ORM Usage
FuelPHP’s ORM simplifies database interactions. |
Example (Retrieving Data):
|
Example (Creating Data):
|
Relationships
FuelPHP supports various relationship types (one-to-one, one-to-many, many-to-many). |
Example (One-to-Many in Model_User):
|
Now you can access the user’s posts:
|
Query Builder
For more complex queries, you can use the Query Builder. |
Example:
|