Invalidate field from controller
I have an action/view that is going to be used for reporting purposes, no saving of data involved.
I want some form elements to be valid/invalid and if invalid, some errors to be shown.
What is the most CakePHPi开发者_JAVA技巧sh way for showing errors in form fields that are not based on a model?
Even if you're not getting or saving your data from a database table, you still need a model for validation rules, that's the proper MVC way. You can set
var $useTable = false;
In your model if you're not planning on saving/reading anything. You can then use your model to just set your validation rules and messages.
You can validate your data without saving, within the controller like so:
$this->ModelName->validates()
For more information, please refer here: Validating Data from the Controller
精彩评论