使控制器中的字段无效

发布于 2024-12-09 18:00:04 字数 115 浏览 5 评论 0原文

我有一个将用于报告目的的操作/视图,不涉及保存数据。

我希望某些表单元素有效/无效,如果无效,则显示一些错误。

在不基于模型的表单字段中显示错误的最 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

各自安好 2024-12-16 18:00:04

即使您没有从数据库表中获取或保存数据,您仍然需要一个验证规则模型,这就是正确的 MVC 方式。 则可以在模型中进行设置

var $useTable = false;

如果您不打算保存/读取任何内容, 。然后,您可以使用模型来设置验证规则和消息。

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.

巴黎夜雨 2024-12-16 18:00:04

您可以在控制器内验证数据而无需保存,如下所示:

$this->ModelName->validates()

有关更多信息,请参阅此处:验证来自控制器的数据

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文