MVC - PHP 会话验证
从MVC验证:在哪里验证?中的这个问题,我同意这个想法在引发任何数据库调用之前,在模型中进行验证。
但是,我对这种情况感到困惑:我有这种形式,在将行 ID 渲染回浏览器之前将其存储到会话中。它的作用就像一个令牌。提交表单时,会检查表单中的ID和会话中的ID是否相同。该操作与数据库完全无关。
检查这个ID是控制器的工作还是模型的工作?
From this question in MVC validation: where to validate?, i agree to the idea that validation takes place in the model before raising any DB calls.
however, i am confused regarding this situation: i have this form that stores the row ID into session before it is rendered back to the browser. it works like a token. when the form is submitted, it checks whether the ID from the form and ID from the session are the same.the operation has no relation to the database at all.
is the checking of this ID the work of the controller or the model?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Faux MVC:在控制器中进行。控制器处理大部分业务和行为逻辑,而模型处于非活动参与者状态(不知道它在 MVC 三元组中的使用)或者只是数据库存储的哑接口。
真正的MVC:会话数据是业务逻辑。这是应用程序状态的另一种模型。如果它已经驻留在服务器端会话存储中,则它不是用户输入(控制器实际上的用途)。
最后,克服用词不当。 MVC 是过去的流行词。 (并且在此之前早已被 MVP 和 PAC 取代)。 PHP 领域发生的变种与 MVC 无关。无论实施如何,尝试“正确”地做到这一点都将失败。请参阅https://stackoverflow.com/questions/1549857/simple-php-mvc-framework /1549970#1549970
Faux MVC: Do it in the controller. The controller handles most of the business and behaviour logic, whereas the model is in inactive particapant (unaware of its use in the MVC triad) or only a dumb interface to the database storage.
Real MVC: Sesssion data is business logic. It's another model for application state. It's not user-input (what controllers actually are for) if it already resides in a server-side session store.
Lastly, get over the misnomer. MVC is yesteryears buzzword. (And had long been superseded by MVP and PAC before that). The variant perpetrated in PHP land has nothing to do with MVC. Trying to do it "properly" is going to fail, no matter the implementation. See https://stackoverflow.com/questions/1549857/simple-php-mvc-framework/1549970#1549970
控制器或助手,取决于验证的类型,
我认为
Controller or Helper, depending on type of the validation,
i think