🔥 CodeIgniter
Beginner
What is a Controller in CodeIgniter 4?
Answer
In CodeIgniter 4, a Controller handles HTTP requests and returns responses. Controllers are stored in app/Controllers/ and extend CodeIgniter\Controller (or BaseController for common functionality). Example: namespace App\Controllers; class Blog extends BaseController { public function index() { return view("blog/index"); } }. Access request data with $this->request->getPost("field"), getGet(), or getVar(). Return a view: return view("viewname", $data). Return JSON: return $this->response->setJSON($data). The BaseController in app/Controllers/BaseController.php is where you initialize helpers, libraries, and properties shared by all controllers. Every public method can be a routable action.