agentleFS
AnyOrgNameAnyOrgName/php-skills/skills/cakephp/validation/SKILL.md

validation

Skill4 starsChanged 4 months agoMITView on GitHub

Validate data with CakePHP — Validator rules for shape checks during marshalling and application rules for database-aware integrity, applied at the boundary. Use when the user needs rules that depend on the database, such as uniqueness or foreign-key existence, checked before a save commits; the user wants a custom validation rule, a named validation set, or a rule that applies only under certain conditions; the user needs to validate the shape of submitted data (required, length, format) before it is persisted in CakePHP. Keywords: cakephp, validation, validator, application-rules, rules-checker, input.

20 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use testing.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • NVIDIASkill

    testing

    Run Python and Rust tests for physicsnemo-curator using uv + pytest with coverage reporting via pytest-cov, and cargo-nextest for Rust tests. Includes benchmark workflows with pytest-benchmark and criterion.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 20 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Do not model "may this user perform this action" as a validation rule.

    line 66
  2. Distinctive:

    Do not use this skill for Symfony Validator, Laravel validation, or Respect/Validation.

    line 67
  3. Very specific:

    Treat a falsey save() return (or a marshalled entity with getErrors()) as the signal that validation failed, and surface those messages …

    line 88
  4. Very specific:

    Use requirePresence('field') to require the key to exist in the data, and notEmptyString('field') (or the typed notEmpty variant) to reject …

    line 91

“Common” is measured: kept by at least 6 in 10 of the 20 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md
<!-- generated: do not edit — source: knowledge/atoms/cakephp/validation/ --><!-- schema: atomVersion=3 skillVersion=2 graphVersion=1 --><!-- compile: @php-skills/compiler v1.0.0 (deterministic build) -->

CakePHP Validation

When to use

  • The user needs rules that depend on the database, such as uniqueness or foreign-key existence, checked before a save commits.
  • The user wants a custom validation rule, a named validation set, or a rule that applies only under certain conditions.
  • The user needs to validate the shape of submitted data (required, length, format) before it is persisted in CakePHP.

When NOT to use

  • Do not model "may this user perform this action" as a validation rule; that is an authorization concern handled by policies, not the Validator.
  • Do not use this skill for Symfony Validator, Laravel validation, or Respect/Validation; the Validator and RulesChecker API is CakePHP specific.

Core guidance

  • Enforce uniqueness with isUnique in buildRules, not the Validator — Add $rules->add($rules->isUnique(['email'])) in buildRules() for uniqueness, rather than trying to check it in the shape Validator.
  • Validate shape with a Validator, integrity with application rules — Put format and presence checks (required, email, length) in validationDefault() where they run during marshalling; put database-dependent checks (unique, exists) in buildRules() where they run at save time.

Quick recipe

  1. In the Table's validationDefault(Validator $validator), chain rules like requirePresence('email'), notEmptyString('email'), and email('email'). (verify: Marshalling malformed data populates the entity's errors)
  2. In buildRules(RulesChecker $rules), add $rules->add($rules->isUnique(['email'])) and any existsIn foreign-key checks, backed by matching database constraints. (verify: Saving a duplicate email fails with a rule error)
  3. Marshal input with patchEntity(), call save(), and on a falsey result read $entity->getErrors() to display per-field messages. (verify: Valid data persists; invalid data returns messages and saves nothing)

Best practices

  • Treat a falsey save() return (or a marshalled entity with getErrors()) as the signal that validation failed, and surface those messages instead of assuming success
  • Define alternate validation methods (e.g
  • Use requirePresence('field') to require the key to exist in the data, and notEmptyString('field') (or the typed notEmpty variant) to reject blank values; combine them when a field must be both present and non-empty

Anti-patterns

Anti-patternWhy it failsDo instead
Encoding permission checks as validation rulesMixing authorization into validation hides access control in the model layer, where it is easy to forget and hard to audit.Keep permission checks in authorization policies and reserve validation for data correctness.
Relying on client-side validation for correctnessClient validation is trivially bypassed with a direct request, so unchecked data reaches the database.Enforce every rule server-side in the Table and use client validation only to improve the user experience.
Validating with manual checks in the controllerController-side checks drift from the model's rules, get duplicated per action, and are skipped by other save paths.Declare the rules once in the Table's Validator/RulesChecker so every write path enforces them.

See references/anti-patterns.md.

Common mistakes

  1. Confusing requirePresence with notEmpty — Adding only requirePresence still lets an empty string through, and adding only notEmpty still lets a missing key through. Fix: Combine requirePresence and the appropriate notEmpty* rule when a field must be both present and filled.
  2. Ignoring the save return value hides validation failures — Calling save() and ignoring its return lets a validation or rule failure pass silently, so nothing is persisted but the code continues. Fix: Branch on the boolean result (or use saveOrFail where an exception is appropriate) and read getErrors() on failure.
  3. Uniqueness placed in the Validator never runs at save — A uniqueness check written into the shape Validator does not have database access at marshalling time and cannot reliably enforce uniqueness. Fix: Move uniqueness to buildRules() with isUnique, backed by a database unique index.

Version notes

  • CakePHP 5 tightens Validator and rule signatures — CakePHP 5 (PHP 8.1+) uses stricter parameter and return types on the Validator and RulesChecker methods, so custom rules and validationDefault() overrides should adopt the typed signatures used in the 5.x API.

Security

  • Always validate on the server; never trust client checks — Define the authoritative rules in the Table's Validator and RulesChecker and run them on every write path; treat client-side or JavaScript validation as UX only, and pair uniqueness rules with real database constraints.

Testing

  • Activation and decision behavior are verified in eval/scenarios/cakephp/validation.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: cakephp/controllers, cakephp/orm, php/typed-properties

<!-- graph-fragment: graph/fragments/cakephp/validation.yaml -->

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.