Friday, November 13
Trending
- Microsoft 365 Outage: Outlook, Teams and Copilot Down. What We Know
- Diwali Online Shopping Scams 2026: 10 Ways to Stay Safe
- 10 Best DDoS Protection Services for 2027
- 12 Best Web Application Firewalls (WAF) for 2027
- Best Ethical Hacking Tools in 2027: Free & Paid Picks
- Software supply chain attacks 2026: Timeline and developer checklist
- Binance Hack: $6.3 Billion Drained in the Largest Crypto Theft Ever. What We Know So Far
- This Site Uses XSLT Chrome Warning Explained: How to Fix It
What is a Controller?
A Controller receives the user input validates it, and then passes the input to the Model. It performs interaction on the model objects. It is a simple class file. The name of the class is associated with URI. The first letter of a class name must be capital.
Controller Example – CodeIgniter 3
<?php
class Home extends CI_Controller {
public function index() {
echo "Welcome to CodeIgniter 3";
}
}
?>Run in Browser:
http://localhost/project/index.php/home/
Controller Example – CodeIgniter 4
<?php
namespace App\Controllers;
class Home extends BaseController {
public function index() {
echo "Welcome to CodeIgniter 4";
}
}
?>Run the following command in cmd/terminal from the project’s root directory:
> php spark serve
http://localhost:8080Run in Browser:
http://localhost:8080/index.php/Home/index
In the above example, Home.php is a default controller. You can alter the default namespace, controller, and method from /app/Config/Routes.php.



