Filter
in package
implements
RouteAttributeInterface
Filter Attribute
Applies CodeIgniter filters to controller classes or methods. Filters can perform operations before or after controller execution, such as authentication, CSRF protection, rate limiting, or request/response manipulation.
Limitations:
- Filter must be registered in Config\Filters.php or won't be found
- Does not validate filter existence at attribute definition time
- Cannot conditionally apply filters based on runtime conditions
- Class-level filters cannot be overridden or disabled for specific methods
Security Considerations:
- Filters run in the order specified; authentication should typically come first
- Don't rely solely on filters for critical security; validate in controllers too
- Ensure sensitive filters are registered as globals if they should apply site-wide
Attributes
- #[Attribute]
- \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE
Table of Contents
Interfaces
Properties
Methods
- __construct() : mixed
- after() : ResponseInterface|null
- Process the attribute after the controller is executed.
- before() : RequestInterface|ResponseInterface|null
- Process the attribute before the controller is executed.
- getFilters() : array<string|int, mixed>
Properties
$by
public
string
$by
$having
public
array<string|int, mixed>
$having
= []
Methods
__construct()
public
__construct(string $by[, array<string|int, mixed> $having = [] ]) : mixed
Parameters
- $by : string
- $having : array<string|int, mixed> = []
after()
Process the attribute after the controller is executed.
public
after(RequestInterface $request, ResponseInterface $response) : ResponseInterface|null
Parameters
- $request : RequestInterface
- $response : ResponseInterface
Return values
ResponseInterface|null —Return ResponseInterface to replace the response Return null to use the existing response
before()
Process the attribute before the controller is executed.
public
before(RequestInterface $request) : RequestInterface|ResponseInterface|null
Parameters
- $request : RequestInterface
Return values
RequestInterface|ResponseInterface|null —Return RequestInterface to replace the request Return ResponseInterface to short-circuit and send response Return null to continue normal execution
getFilters()
public
getFilters() : array<string|int, mixed>