controllers
Skill4 starsChanged 4 months agoMITView on GitHub
Build CodeIgniter 4 controllers — extend BaseController, map request lifecycle to methods, read request and response services, and return typed responses. Use when the user wants a CodeIgniter controller to extend BaseController to share helpers, models, and services across actions; the user needs to handle an incoming HTTP request in CodeIgniter 4 by writing a controller class and action method; the user needs a CodeIgniter controller action to return a view, JSON, or redirect using the response service. Keywords: codeigniter, controllers, basecontroller, request-lifecycle, response, mvc.
In this repository119 other files it gives its agents.
- strategy-bitrix-d7-incrementalSkill
- strategy-explicit-over-magicSkill
- strategy-framework-conventionsSkill
- strategy-legacy-safe-editsSkill
- strategy-minimal-diffSkill
- strategy-no-untested-refactorSkill
- strategy-preserve-public-apiSkill
- strategy-readonly-immutabilitySkill
- strategy-security-firstSkill
- strategy-test-drivenSkill
- openapiSkill
- paginationSkill
- rest-designSkill
- versioningSkill
- cqrsSkill
- dependency-inversionSkill
- hexagonalSkill
- repository-patternSkill
- service-layerSkill
- bitrixSkill
- findings-reportSkill
- laravelSkill
- performanceSkill
- phpSkill
- project-analysisSkill
- refactoringSkill
- roi-prioritizationSkill
- securitySkill
- stack-detectionSkill
- cache-layersSkill
- component-engineSkill
- d7-eventsSkill
- d7-loaderSkill
- d7-orm-queriesSkill
- iblock-elementsSkill
- kernel-main-moduleSkill
- localizationSkill
- controllersSkill
- ormSkill
- validationSkill
- query-builderSkill
- routingSkill
- autoload-psr4Skill
- dependency-managementSkill
- scriptsSkill
- connection-poolingSkill
- mysql-indexingSkill
- redisSkill
- transactionsSkill
- ci-github-actionsSkill
- deployment-strategiesSkill
- docker-phpSkill
- env-configSkill
- associationsSkill
- entities-mappingSkill
- orm-basicsSkill
- entity-apiSkill
- module-developmentSkill
- routing-controllersSkill
- formsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 4 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 65
Do not use this skill to place heavy business rules or persistence logic inside the controller.
- Distinctive: line 66
Do not apply this skill to CodeIgniter 3 projects.
- Very specific: line 78
Create App\Controllers\Widgets extends BaseController and add a public action method such as show($id) that the router can reach.
- Very specific: line 87
Add a _remap($method, ...$params) method only when you must intercept how a controller dispatches to its actions.
- Very specific: line 89
Read input with $this->request->getPost('key'), getGet(), or getVar() instead of touching $_POST, $_GET, or $_REQUEST directly
- Distinctive: line 91
Keep each action small: read input, call a model or service for domain work, then return a response
- Distinctive: line 116
Not applicable — no I/O, auth, or untrusted input.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<!-- generated: do not edit — source: knowledge/atoms/codeigniter/controllers/ --><!-- schema: atomVersion=3 skillVersion=2 graphVersion=1 --><!-- compile: @php-skills/compiler v1.0.0 (deterministic build) -->CodeIgniter 4 Controllers
When to use
- The user wants a CodeIgniter controller to extend BaseController to share helpers, models, and services across actions.
- The user needs to handle an incoming HTTP request in CodeIgniter 4 by writing a controller class and action method.
- The user needs a CodeIgniter controller action to return a view, JSON, or redirect using the response service.
When NOT to use
- Do not use this skill to place heavy business rules or persistence logic inside the controller; that belongs in a model or service class.
- Do not apply this skill to CodeIgniter 3 projects; CI3 uses CI_Controller, the loader, and a different request model.
Core guidance
- Extend BaseController, not the framework Controller directly — Have app controllers extend
App\Controllers\BaseControllerrather thanCodeIgniter\Controllerdirectly, and put shared helpers, models, and services ininitController()or properties on BaseController. - Return the response object instead of echoing output — Return a value from the action —
view(...),$this->response->setJSON(...), orredirect()->to(...)— instead of callingechoorprintdirectly.
Quick recipe
- Create
App\Controllers\Widgets extends BaseControllerand add a public action method such asshow($id)that the router can reach. (verify: Visiting the mapped route reaches the action) - Inside the action, read input via
$this->request->getVar('id')and fetch data withmodel(WidgetModel::class)->find($id)instead of querying inline. (verify: The action returns model data for a known id) - Return
view('widgets/show', $data)for HTML or$this->response->setJSON($data)for an API, and use$this->response->setStatusCode(404)when a record is missing. (verify: A missing record yields a 404, not a 200 with an empty body)
Best practices
- Add a
_remap($method, ...$params)method only when you must intercept how a controller dispatches to its actions; otherwise let the router call the method - Read input with
$this->request->getPost('key'),getGet(), orgetVar()instead of touching$_POST,$_GET, or$_REQUESTdirectly - Keep each action small: read input, call a model or service for domain work, then return a response
Anti-patterns
| Anti-pattern | Why it fails | Do instead |
| Fat controller with domain and query logic inline | Fat controllers cannot be unit-tested without HTTP and duplicate logic across actions. | Move data access to a model and rules to a service; the action orchestrates and returns a response. |
| Instantiating models with new instead of the service | Direct construction bypasses shared configuration and connection reuse and makes dependencies hard to swap in tests. | Resolve models via model(SomeModel::class) or inject them through BaseController. |
| Reading superglobals inside the controller | Superglobals bypass request normalization and filtering and cannot be substituted in tests. | Read input through the request service ($this->request->getPost() / getGet()). |
See references/anti-patterns.md.
Common mistakes
- Request is not ready in the constructor — Reading
$this->requestinside a controller__construct()fails because the request is injected later. Fix: Do setup that needs the request ininitController()or the action, not in the constructor. - Echoing output breaks status codes and filters — Calling
echoin an action sends body bytes before CodeIgniter finalizes the response. Fix: Returnview(...)or a response object; let CodeIgniter emit the body during finalization. - Every public method is a routable endpoint — With auto-routing, any public controller method becomes a URL-reachable endpoint. Fix: Mark helpers
protected/private, or disable auto-routing and declare only intended routes explicitly.
Version notes
- CI4 introduced BaseController and initController — CodeIgniter 4.0 replaced CI3 CI_Controller with a namespaced BaseController and an
initController()lifecycle hook.
Security
- Not applicable — no I/O, auth, or untrusted input.
Testing
- Activation and decision behavior are verified in
eval/scenarios/codeigniter/controllers.yaml.
Additional resources
- references/anti-patterns.md
- references/core.md
- references/examples.md
- references/pitfalls.md
- references/recipes.md
- references/version-differences.md
Knowledge graph
Related: codeigniter/routing, php/typed-properties
<!-- graph-fragment: graph/fragments/codeigniter/controllers.yaml -->Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

