CodeIgniter v4.7 API

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

RouteAttributeInterface

Properties

$by  : string
$having  : array<string|int, mixed>

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

$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> = []

getFilters()

public getFilters() : array<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results