🔥 CodeIgniter Intermediate

What is CI4 route filters with arguments?

Why Interviewers Ask This

This tests whether you can apply CodeIgniter knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.

Answer

CodeIgniter 4 Filters support arguments allowing one filter class to behave differently based on passed parameters. Apply a filter with arguments: $routes->get("admin/dashboard", "Admin::index", ["filter" => "roles:admin,superuser"]). In the filter's before() method, access arguments: public function before(RequestInterface $request, $arguments = null) { if (!in_array($currentUser->role, $arguments)) { return redirect()->to("/")->with("error", "Access denied"); } }. Register filters with aliases in app/Config/Filters.php: $aliases = ["roles" => App\Filters\RoleFilter::class]. Multiple arguments: ["filter" => "throttle:60,1"] receives ["60", "1"]. You can apply filters per HTTP method: $methods = ["post" => ["csrf"]]. Filter arguments make a single filter class flexible enough to handle multiple permission levels, throttle rates, or feature flags without creating separate filter classes for each variation.

Pro Tip

Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a CodeIgniter codebase.