Welcome to CodeIgniter 4
Relevant source files
The following files were used as context for generating this wiki page:
CodeIgniter 4 is a modern PHP web framework designed to be light, fast, flexible, and secure. It is built for PHP developers who need a simple and elegant toolkit to create full-featured web applications. The framework is known for its small footprint, exceptional performance, and clear documentation, requiring nearly zero initial configuration to get started.
Sources: README.md:3, source/index.rst:11-16
This repository (ci4_userguide) is a read-only mirror containing the source for the official user guide. It is automatically built and published as part of the framework's release workflow. For development, contributions, or to report issues with the user guide, please refer to the main CodeIgniter 4 repository.
Sources: README.md:6-11
Core Philosophy
CodeIgniter 4 is built on a set of principles that guide its design and development. These goals ensure the framework remains powerful yet easy to use.
| Feature | Description |
|---|---|
| Small Footprint | The core system is a lean set of libraries, with additional libraries loaded dynamically as needed. |
| Performance | The framework is designed to be as fast as possible, a key tenet of the CodeIgniter philosophy. |
| Clear Docs | The user guide is comprehensive and clear, intended to be a primary resource for learning and using CI4. |
| No Rules | CodeIgniter does not force a restrictive coding style and provides flexibility to the developer. |
| Simple Solutions | The framework avoids over-complication and favors simple, pragmatic solutions to problems. |
| Security | Built-in features provide protection against common security threats like XSS and CSRF. |
Sources: source/index.rst:11-21
Server Requirements
To run CodeIgniter 4, your server environment must meet the following requirements:
- PHP version 7.4 or newer
- The following PHP extensions must be enabled:
intlmbstringjsonxml
Sources: source/index.rst:26-33
Application Flow: The MVC Pattern
CodeIgniter is based on the Model-View-Controller (MVC) architectural pattern, which separates application logic from presentation. This separation makes the code cleaner, more organized, and easier to maintain.
- Model: Manages the application's data and business logic. It is responsible for interacting with the database to retrieve, insert, and update information.
- View: Handles the presentation layer. It is typically an HTML file with minimal PHP, responsible for displaying the data provided by the controller.
- Controller: Acts as the intermediary between the Model and the View. It receives user requests, interacts with the Model to fetch data, and then passes that data to the View to be rendered and sent back to the user.
Sources: source/concepts/mvc.rst:5-18
The following diagram illustrates the typical data flow in a CodeIgniter 4 application.
This diagram shows how a user request is routed to a controller, which uses a model to fetch data and a view to create the final response.
Sources: source/concepts/mvc.rst:1-18
Getting Started
Installation
There are three primary methods for installing CodeIgniter 4. The recommended approach is using Composer, as it simplifies dependency management and updates.
The diagram below shows the decision process for choosing an installation method.
| Method | Description |
|---|---|
| Composer | (Recommended) The easiest method. Manages dependencies and allows for simple updates (composer update). |
| Manual Installation | Download a zip or tarball of the latest release. This is simpler but requires manual updates and dependency management. |
| Git Installation | Clone the repository. This method is for developers who want to contribute to the framework or stay on the cutting edge of development. |
Sources: source/installation/index.rst:29-31, 74-76, 110-112
Running Your App
Once installed, you can run the built-in development server using the spark command-line tool from the project root:
php spark serve
This will start a local server, typically at http://localhost:8080.
Sources: source/installation/index.rst:20-22
Tutorial: Building Your First Application
The user guide includes a tutorial for building a simple news application. This exercise demonstrates the core concepts of CI4 in a practical way. The process involves creating static pages, handling routing, setting up a database, creating a model to fetch news items, and displaying them in views.
The following sequence diagram illustrates the flow of a user requesting to view all news items in the tutorial application.
This diagram shows the controller (NewsController) handling the request, using the model (NewsModel) to get data, and passing it to a view for rendering.
Sources: source/tutorial/index.rst
User Guide and Contributions
The ci4_userguide repository exists solely to publish the user guide. It is not the place for development or pull requests. All contributions, including documentation fixes, should be directed to the main framework repository.
Sources: README.md:6-14
- For code or documentation fixes: Submit a pull request to the codeigniter4/codeigniter4 repository.
- For questions or feature discussions: Post on the official CodeIgniter Forum.
Conclusion
CodeIgniter 4 provides a robust yet lightweight foundation for building modern PHP applications. Its adherence to the MVC pattern, minimal configuration, and comprehensive documentation make it an excellent choice for developers of all skill levels. By following the installation steps and the introductory tutorial, new users can quickly become productive and leverage the framework's power and flexibility.
Sources: README.md:3, source/index.rst:11-21