Convert Figma logo to code with AI

codeigniter4 logoCodeIgniter4

Open Source PHP Framework (originally from EllisLab)

5,296
1,894
5,296
88

Top Related Projects

78,107

Laravel is a web application framework with expressive, elegant syntax. We’ve already laid the foundation for your next big idea — freeing you to create without sweating the small things.

29,606

The Symfony PHP framework

14,227

Yii 2: The Fast, Secure and Professional PHP Framework

8,679

CakePHP: The Rapid Development Framework for PHP - Official Repository

11,931

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.

64,773

Fast, unopinionated, minimalist web framework for node.

Quick Overview

CodeIgniter 4 is a modern, open-source PHP web application framework that provides a robust set of tools and libraries for building dynamic and scalable web applications. It is designed to be lightweight, fast, and easy to use, making it a popular choice for developers who want to build high-performance web applications quickly.

Pros

  • Lightweight and Fast: CodeIgniter 4 is designed to be lightweight and fast, with a small footprint and efficient performance.
  • Modular Design: The framework has a modular design, allowing developers to easily add or remove components as needed, making it highly customizable.
  • Extensive Documentation: CodeIgniter 4 has comprehensive documentation that covers a wide range of topics, making it easy for developers to get started and learn the framework.
  • Active Community: CodeIgniter 4 has an active community of developers who contribute to the project, provide support, and create a wide range of third-party libraries and tools.

Cons

  • Limited Scalability: While CodeIgniter 4 is suitable for small to medium-sized web applications, it may not be the best choice for large-scale, enterprise-level projects that require more advanced features and scalability.
  • Older Codebase: CodeIgniter 4 is based on an older version of the PHP language, which may not take advantage of the latest language features and best practices.
  • Limited Flexibility: The framework's simplicity and ease of use can also be a limitation, as it may not provide the same level of flexibility and customization as some other PHP frameworks.
  • Steep Learning Curve: While the documentation is comprehensive, the framework's architecture and design patterns may have a steeper learning curve for developers who are new to CodeIgniter or PHP web development.

Code Examples

Here are a few code examples that demonstrate the usage of CodeIgniter 4:

  1. Routing:
// routes.php
$routes->get('/', 'Home::index');
$routes->get('about', 'About::index');
$routes->post('contact', 'Contact::submit');

This code sets up the routing for a simple web application, defining three routes: the home page, an about page, and a contact form submission.

  1. Controller:
// app/Controllers/Home.php
namespace App\Controllers;

class Home extends BaseController
{
    public function index()
    {
        return view('home');
    }
}

This code defines a simple controller that renders the home view.

  1. Model:
// app/Models/UserModel.php
namespace App\Models;

use CodeIgniter\Model;

class UserModel extends Model
{
    protected $table = 'users';
    protected $primaryKey = 'id';

    protected $allowedFields = ['name', 'email', 'password'];
}

This code defines a model for the users table, providing a simple interface for interacting with the database.

  1. View:
<!-- app/Views/home.php -->
<!DOCTYPE html>
<html>
<head>
    <title>Welcome to CodeIgniter 4</title>
</head>
<body>
    <h1>Hello, CodeIgniter 4!</h1>
    <p>This is the home page.</p>
</body>
</html>

This code defines a simple HTML view that displays a welcome message.

Getting Started

To get started with CodeIgniter 4, follow these steps:

  1. Install CodeIgniter 4: You can install CodeIgniter 4 using Composer, the popular PHP dependency manager. Run the following command in your terminal:

    composer create-project codeigniter4/appstarter my-project
    
  2. Start the development server: CodeIgniter 4 comes with a built-in development server. You can start it by running the following command in your terminal:

    cd my-project
    php spark serve
    
  3. Explore the project structure: The my-project directory contains the following important directories and files:

    • app/: This directory contains your application's code, including controllers, models, views, and other components.
    • public/: This directory contains the web-accessible directory

Competitor Comparisons

78,107

Laravel is a web application framework with expressive, elegant syntax. We’ve already laid the foundation for your next big idea — freeing you to create without sweating the small things.

Pros of Laravel

  • More extensive ecosystem with a larger community and more packages
  • Built-in features like Eloquent ORM and Artisan CLI for rapid development
  • Better support for modern PHP practices and design patterns

Cons of Laravel

  • Steeper learning curve, especially for beginners
  • Heavier framework with more overhead, potentially impacting performance
  • More complex configuration and setup process

Code Comparison

Laravel route definition:

Route::get('/users', [UserController::class, 'index']);

CodeIgniter4 route definition:

$routes->get('/users', 'UserController::index');

Laravel Eloquent ORM query:

$users = User::where('active', 1)->get();

CodeIgniter4 Model query:

$users = $this->userModel->where('active', 1)->findAll();

Both frameworks offer modern PHP development experiences, but Laravel provides a more feature-rich environment at the cost of complexity, while CodeIgniter4 focuses on simplicity and performance. Laravel's extensive ecosystem and built-in tools make it suitable for large-scale applications, whereas CodeIgniter4's lightweight nature and ease of use make it ideal for smaller projects or developers who prefer a minimalist approach.

29,606

The Symfony PHP framework

Pros of Symfony

  • More extensive feature set and robust ecosystem
  • Better suited for large, complex applications
  • Strong dependency injection and service container

Cons of Symfony

  • Steeper learning curve and more complex architecture
  • Potentially slower performance due to larger codebase
  • Higher resource requirements for smaller projects

Code Comparison

Symfony route definition:

/**
 * @Route("/hello/{name}", name="hello")
 */
public function hello($name)
{
    return new Response("Hello, " . $name);
}

CodeIgniter4 route definition:

$routes->get('hello/(:segment)', 'Hello::index/$1');

public function index($name)
{
    return "Hello, " . $name;
}

Both frameworks offer MVC architecture and routing capabilities, but Symfony provides more advanced features and flexibility at the cost of complexity. CodeIgniter4 is generally simpler and easier to learn, making it a good choice for smaller projects or developers new to PHP frameworks. Symfony excels in large-scale applications and offers more built-in tools for enterprise-level development. The choice between the two often depends on project requirements, team expertise, and scalability needs.

14,227

Yii 2: The Fast, Secure and Professional PHP Framework

Pros of Yii2

  • More comprehensive and feature-rich framework
  • Better support for large-scale enterprise applications
  • Stronger emphasis on security features out-of-the-box

Cons of Yii2

  • Steeper learning curve for beginners
  • Heavier and potentially slower for smaller projects
  • Less frequent updates compared to CodeIgniter4

Code Comparison

Yii2 routing example:

'rules' => [
    'post/<id:\d+>' => 'post/view',
    'posts/<tag>' => 'post/index',
    '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
],

CodeIgniter4 routing example:

$routes->get('post/(:num)', 'Post::view/$1');
$routes->get('posts/(:segment)', 'Post::index/$1');
$routes->add('(:controller)/(:action)', '$1::$2');

Both frameworks offer powerful routing capabilities, but Yii2's approach is more declarative, while CodeIgniter4's is more procedural. Yii2's routing configuration is typically done in a single file, whereas CodeIgniter4 allows for more distributed routing definitions across the application.

8,679

CakePHP: The Rapid Development Framework for PHP - Official Repository

Pros of CakePHP

  • More comprehensive ORM with advanced features like lazy loading and eager loading
  • Built-in security features like CSRF protection and SQL injection prevention
  • Extensive plugin ecosystem for added functionality

Cons of CakePHP

  • Steeper learning curve due to its more complex architecture
  • Slower performance compared to CodeIgniter, especially for smaller applications
  • Less flexibility in terms of customization and overriding core components

Code Comparison

CakePHP controller example:

class ArticlesController extends AppController
{
    public function index()
    {
        $articles = $this->Articles->find('all');
        $this->set(compact('articles'));
    }
}

CodeIgniter4 controller example:

class Articles extends BaseController
{
    public function index()
    {
        $model = new ArticleModel();
        $data['articles'] = $model->findAll();
        return view('articles/index', $data);
    }
}

Both frameworks use a similar MVC structure, but CakePHP's approach is more convention-driven, while CodeIgniter4 offers more explicit control over data passing and view rendering. CakePHP's ORM is more feature-rich out of the box, while CodeIgniter4's implementation is simpler and more lightweight.

11,931

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.

Pros of Slim

  • Lightweight and minimalistic, offering faster performance for simple applications
  • Highly flexible and customizable, allowing developers to choose their preferred components
  • Easy to learn and implement, with a gentle learning curve for beginners

Cons of Slim

  • Less built-in functionality compared to CodeIgniter4, requiring more manual setup
  • Smaller community and ecosystem, potentially leading to fewer resources and third-party libraries
  • Limited out-of-the-box features, which may increase development time for complex applications

Code Comparison

Slim route definition:

$app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
    $name = $args['name'];
    $response->getBody()->write("Hello, $name");
    return $response;
});

CodeIgniter4 route definition:

$routes->get('/hello/(:segment)', 'Home::hello/$1');

// In Home controller
public function hello($name)
{
    return "Hello, $name";
}

Both frameworks offer simple routing, but Slim's approach is more compact and functional, while CodeIgniter4 follows a more traditional MVC structure. Slim's minimalistic nature is evident in its concise code, while CodeIgniter4 provides a more structured approach with separate controller methods.

64,773

Fast, unopinionated, minimalist web framework for node.

Pros of Express

  • Lightweight and minimalist, allowing for greater flexibility and customization
  • Extensive ecosystem with a wide range of middleware and plugins
  • Better performance and scalability for large-scale applications

Cons of Express

  • Steeper learning curve for beginners due to its unopinionated nature
  • Requires more setup and configuration compared to CodeIgniter's out-of-the-box functionality
  • Less built-in security features, requiring developers to implement their own or rely on third-party modules

Code Comparison

Express route handling:

app.get('/', (req, res) => {
  res.send('Hello World!');
});

CodeIgniter4 route handling:

$routes->get('/', 'Home::index');

// In Home controller
public function index()
{
    return 'Hello World!';
}

Express offers a more concise syntax for simple route handling, while CodeIgniter4 follows a more structured MVC approach. Express provides direct access to request and response objects, whereas CodeIgniter4 abstracts these details within the controller method.

Both frameworks have their strengths, with Express offering more flexibility and performance for experienced developers, while CodeIgniter4 provides a more structured and beginner-friendly environment with built-in features for rapid development.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

CodeIgniter 4 Development

PHPUnit PHPStan Psalm Coverage Status Downloads GitHub release (latest by date) GitHub stars GitHub license contributions welcome

What is CodeIgniter?

CodeIgniter is a PHP full-stack web framework that is light, fast, flexible and secure. More information can be found at the official site.

This repository holds the source code for CodeIgniter 4 only. Version 4 is a complete rewrite to bring the quality and the code into a more modern version, while still keeping as many of the things intact that has made people love the framework over the years.

More information about the plans for version 4 can be found in CodeIgniter 4 on the forums.

Documentation

The User Guide is the primary documentation for CodeIgniter 4.

You will also find the current in-progress User Guide. As with the rest of the framework, it is a work in progress, and will see changes over time to structure, explanations, etc.

You might also be interested in the API documentation for the framework components.

Important Change with index.php

index.php is no longer in the root of the project! It has been moved inside the public folder, for better security and separation of components.

This means that you should configure your web server to "point" to your project's public folder, and not to the project root. A better practice would be to configure a virtual host to point there. A poor practice would be to point your web server to the project root and expect to enter public/..., as the rest of your logic and the framework are exposed.

Please read the user guide for a better explanation of how CI4 works!

Repository Management

CodeIgniter is developed completely on a volunteer basis. As such, please give up to 7 days for your issues to be reviewed. If you haven't heard from one of the team in that time period, feel free to leave a comment on the issue so that it gets brought back to our attention.

[!IMPORTANT] We use GitHub issues to track BUGS and to track approved DEVELOPMENT work packages. We use our forum to provide SUPPORT and to discuss FEATURE REQUESTS.

If you raise an issue here that pertains to support or a feature request, it will be closed! If you are not sure if you have found a bug, raise a thread on the forum first - someone else may have encountered the same thing.

Before raising a new GitHub issue, please check that your bug hasn't already been reported or fixed.

We use pull requests (PRs) for CONTRIBUTIONS to the repository. We are looking for contributions that address one of the reported bugs or approved work packages.

Do not use a PR as a form of feature request. Unsolicited contributions will only be considered if they fit nicely into the framework roadmap. Remember that some components that were part of CodeIgniter 3 are being moved to optional packages, with their own repository.

Contributing

We are accepting contributions from the community! It doesn't matter whether you can code, write documentation, or help find bugs, all contributions are welcome.

Please read the Contributing to CodeIgniter.

CodeIgniter has had thousands on contributions from people since its creation. This project would not be what it is without them.

Made with contrib.rocks.

Server Requirements

PHP version 8.1 or higher is required, with the following extensions installed:

[!WARNING]

  • The end of life date for PHP 7.4 was November 28, 2022.
  • The end of life date for PHP 8.0 was November 26, 2023.
  • If you are still using PHP 7.4 or 8.0, you should upgrade immediately.
  • The end of life date for PHP 8.1 will be December 31, 2025.

Additionally, make sure that the following extensions are enabled in your PHP:

  • json (enabled by default - don't turn it off)
  • mysqlnd if you plan to use MySQL
  • libcurl if you plan to use the HTTP\CURLRequest library

Running CodeIgniter Tests

Information on running the CodeIgniter test suite can be found in the README.md file in the tests directory.