Skip to content

feat: Add Query, Header and Cookie attributes for direct Controller injection#10128

Draft
patel-vansh wants to merge 1 commit intocodeigniter4:4.8from
patel-vansh:feat/from-query-from-header-attributes
Draft

feat: Add Query, Header and Cookie attributes for direct Controller injection#10128
patel-vansh wants to merge 1 commit intocodeigniter4:4.8from
patel-vansh:feat/from-query-from-header-attributes

Conversation

@patel-vansh
Copy link
Copy Markdown
Contributor

Description
This PR introduces attribute-driven parameter resolution for controller methods, allowing HTTP request data to be injected directly into method parameters using PHP 8 attributes.

It enhances CodeIgniter’s controller parameter resolution system while preserving existing routing, form request, and default parameter behaviors.

Controller method parameters can now be annotated with request-source attributes:

  • #[Query] → Inject query string values
  • #[Header] → Inject HTTP header values
  • #[Cookie] → Inject cookie values

Example

class MyController {
    public function index(
        int $id,
        #[Query('limit')] int $limit = 10,
        #[Header('X-Tenant-Id')] string $tenantId
    ) {
        // $limit and $tenant will be fetched from Query and Header respectively.
        // Passing of parameters to attribute is optional, if no $key is passed to attribute, it'll default to name of the parameter itself
    }
}

Currently, its a draft PR for others to see implementation. I haven't added tests or updated userguide yet.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@github-actions github-actions Bot added the 4.8 PRs that target the `4.8` branch. label Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant