What is CodeIgniter 4's Events system?
Why Interviewers Ask This
Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for CodeIgniter development. It reveals whether you understand the building blocks that more complex concepts rely on.
Answer
CodeIgniter 4's Events system allows executing code at specific points during framework execution. Define events in app/Config/Events.php: Events::on("pre_controller", function() { /* runs before controller */ }). Built-in events: pre_system (very early bootstrap), pre_controller (after routing, before controller), post_controller_constructor (after controller instantiation), post_controller (after controller method), pre_models, post_models. Events allow you to hook into the framework lifecycle without modifying core files — useful for logging, analytics, performance monitoring, or global setup. CI4 events replaced CI3's Hooks system. Each event point can have multiple listeners. Unlike CI3 hooks, CI4 events are simpler and more Pythonic in their design.
Pro Tip
Back up your answer with a specific project or situation. Saying 'In my last CodeIgniter project, I used this when...' immediately makes your answer more credible and memorable.