MVC-错误消息 [英] MVC - error messages

查看:63
本文介绍了MVC-错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建MVC Web应用程序.

I'm creating MVC web application.

在MVC的哪个部分(模型视图控制器)中,我应该保存错误消息,该错误消息可以出现在出现问题的地方,用户应该阅读这些错误消息?

In which part of MVC (model-view-controller), I should save my error messages, that can appear where something goes wrong and user should read them?

当前情况:

型号:

function f()
{
    $data[error] = "Error message"
    return $data;
}

查看:

echo $error 

推荐答案

我的意见是将它们放置在 模型的末端 .对我来说,控制器只是充当中间人,视图不必做太多思考.

My opinion would be to have them at the model's end. For me, the controller just acts as a middleman, and the view should not have to do much thinking..

在我的代码中,VIEW只是简单地准备了前端输出,并获得了需要在页面中显示的数据.它不需要做任何思考,并且所有验证都已经在模型中,因此它只需要专注于显示结果,表单,信息,帮助,提示等.

The VIEW in my code simply prepares the front end output, after being given the data it needs to display in the page. It doesn't have to do any thinking, and all validations are in the model already, so it just has to focus on displaying results, forms, information, help, hint, etc.

我的代码中的CONTROLLER只是为用户(客户端的浏览器请求),模型(进行所有思考)和视图(进行所有显示")进行通信.它不知道用户输入中是否有错误;它只是将输入传递给模型.完成模型后,控制器只需将输出传递到视图即可.

The CONTROLLER in my code just does the communication for the user (client's browser requests), the model (which does all the thinking) and the view (which does all the 'showing'). It wouldn't know that there are errors in the input coming from the user; it merely passes the input to the model. When the model's done, the controller just passes that output to the view.

我的代码中的MODEL负责进行所有思考.它接收来自用户的输入(通过控制器),并执行所需的操作.对于它生成的任何或所有结果和/或错误,它只是将其传递给视图(再次通过控制器),并期望该视图知道该怎么做:显示数据.

The MODEL in my code is responsible for doing all the thinking. It receives the input from the user (via the controller) and does what it needs to do with it. For any or all results and/or errors it generates, it just passes it to the view (again, via the controller) and expects that the view knows what to do: to display the data.

这篇关于MVC-错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆