📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials CodeIgniter 4 CI4 Events and Hooks

CI4 Events and Hooks

4 min read
Hook into pre_controller and post_controller events with Events::on() for logging and profiling.

Events and Hooks

// app/Config/Events.php
use CodeIgniter\Events\Events;

Events::on("user.login", function(object $user) {
    model("ActivityModel")->log($user->id, "logged_in");
});

Events::on("pre_controller", function() {
    log_message("debug", "Request: " . current_url());
});

// Fire custom event
Events::trigger("user.login", $user);