-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
How to validate input fields without using model in Yii2 Rest. #16375
Comments
try it DynamicModel |
It is called "Ad Hoc Validation" https://www.yiiframework.com/doc/guide/2.0/en/input-validation#ad-hoc-validation It allows you to validate any single value with any yii2 validator without any models. If you want to validate more than one or two fields, DynamicModel is preferred approach, as it has simpler syntax than multiple Ad Hoc validators. https://www.yiiframework.com/doc/api/2.0/yii-base-dynamicmodel as rustamwin already suggested |
Thanks @rustamwin @Deele |
Thank you for your question. We advise you to use our community driven resources: If you are confident that there is a bug in the framework, feel free to provide information on how to reproduce it. This issue will be closed for now. This is an automated comment, triggered by adding the label |
In a controller file -
So how to acheive this? |
let's say i have a controller called "trendController".
in index method, there is a logic which need to save some form data which will show some output to user after validation.
Now input data is something like
name
- Should be text only,amount
- Number or decimal only,email
- A valid email,phone
- Only number, no country code..Remember, there is no model play any role here. so how to validate these input in proper yii2 ways.
The text was updated successfully, but these errors were encountered: