Controller
The Controller class serves as the base class for all application controllers. It provides access to configuration and database instances.Namespace
Constructor
__construct()
Initializes the controller with environment configuration and database connection.Behavior
- Loads configuration from
../app/config/config.php - Creates a new Database instance with the loaded configuration
- Assigns the configuration to the
$envproperty - Assigns the database instance to the
$dbproperty
Example
Properties
$env
Stores the application configuration array loaded from the config file.Contains configuration values such as:
host: Database hostport: Database portdatabase: Database nameusername: Database usernamepassword: Database password- Additional application-specific settings
Example
$db
Provides access to the Database instance for executing queries.An instance of the Database class used to:
- Execute SQL queries
- Perform CRUD operations
- Interact with the database connection
Example
Usage Pattern
All application controllers should extend the Controller base class to inherit configuration and database access:Best Practices
- Always extend Controller: All application controllers should extend this base class
- **Use db` property
- **Access config through env` property
- Keep controllers thin: Delegate business logic to Models when possible
See Also
ApiController
Specialized controller for building REST APIs
Router
Route definition and dispatching