Model view controller 在控制器或模型中的何处验证和测试用户输入日期?
在哪里清理/验证/验证用户输入数据?在控制器或模型中?我会选择模型,以便重复使用您的验证。模型应处理数据,控制器应将数据定向到需要去的地方。在控制器中 这样看:您的表单将使用$\u post变量中的表单数据发布到控制器函数。验证控制器功能中的数据,并执行一些DB插入或更新。然后将成功消息显示为视图,如果出现错误,则显示失败消息Model view controller 在控制器或模型中的何处验证和测试用户输入日期?,model-view-controller,codeigniter,Model View Controller,Codeigniter,在哪里清理/验证/验证用户输入数据?在控制器或模型中?我会选择模型,以便重复使用您的验证。模型应处理数据,控制器应将数据定向到需要去的地方。在控制器中 这样看:您的表单将使用$\u post变量中的表单数据发布到控制器函数。验证控制器功能中的数据,并执行一些DB插入或更新。然后将成功消息显示为视图,如果出现错误,则显示失败消息 请参阅CodeIgniter用户指南中的表单验证教程。进行验证的代码必须在模型中,但对该代码的调用必须在控制器中 大概是这样的: class MyAwesomeUserM
请参阅CodeIgniter用户指南中的表单验证教程。进行验证的代码必须在模型中,但对该代码的调用必须在控制器中 大概是这样的:
class MyAwesomeUserModel {
public function isValid()
{
//some code to validate the user
}
}
class MyUserController {
public function myUserAction()
{
//some code to insert the input of the user in the model
if($userModel->isValid()){
//do nice things with the data and send some message/data to the view
} else {
//send 'nice' error messages to the view
}
}
}
这只是我使用的方式,可能不是最好的方式,但它最适合我的应用程序。这才是最重要的,您应该寻找最适合您的应用程序的