What is a Controller in CodeIgniter 4?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex CodeIgniter topics. It also reveals how well you can explain technical ideas to non-experts.
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.
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.