开发者

Invalidate field from controller

开发者 https://www.devze.com 2023-04-13 05:14 出处:网络
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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号