Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
CodeIgniter

Creating Your First Controller

Generate or manually create a controller and wire it to a route.

Creating Your First Controller — a practical guide to create CodeIgniter controller with clear examples you can reuse in real projects.

CodeIgniter Tutorial Series (13/74). Prefer one article? Read the complete CodeIgniter tutorial.

Short description

Create a controller file under `app/Controllers`, add a method, then register a route that calls it.

Steps

  1. Create Products controller.
  2. Add index() method.
  3. Route productsProducts::index.

Spark generate (optional)

php spark make:controller Products

Products controller

<?php
namespace AppControllers;

class Products extends BaseController
{
    public function index()
    {
        return 'Products list';
    }
}

Leave a reply

Your email address will not be published. Required fields are marked *