Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getValidationRules() to model UG page #2316

Merged
merged 1 commit into from
Oct 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions user_guide_src/source/models/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,28 @@ and simply set ``$validationRules`` to the name of the validation rule group you
protected $validationRules = 'users';
}

Retrieving Validation Rules
---------------------------

You can retrieve a model's validation rules by accessing its ``validationRules``
property::

$rules = $model->validationRules;

You can also retrieve just a subset of those rules by calling the accessor
method directly, with options::

$rules = $model->getValidationRules($options);

The ``$options`` parameter is an associative array with one element,
whose key is either "except" or "only", and which has as its
value an array of fieldnames of interest.::

// get the rules for all but the "username" field
$rules = $model->getValidationRules(['except' => ['username']]);
// get the rules for only the "city" and "state" fields
$rules = $model->getValidationRules(['only' => ['city', 'state']]);

Validation Placeholders
-----------------------

Expand Down