使控制器中的字段无效
我有一个将用于报告目的的操作/视图,不涉及保存数据。
我希望某些表单元素有效/无效,如果无效,则显示一些错误。
在不基于模型的表单字段中显示错误的最 CakePHPish 方法是什么?
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 CakePHPish way for showing errors in form fields that are not based on a model?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
即使您没有从数据库表中获取或保存数据,您仍然需要一个验证规则模型,这就是正确的 MVC 方式。 则可以在模型中进行设置
如果您不打算保存/读取任何内容, 。然后,您可以使用模型来设置验证规则和消息。
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
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:
For more information, please refer here: Validating Data from the Controller