What is CodeIgniter 4's Events system?
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.