- 主题:[求助] 初学PHP对MVC的一点疑问
一般来说要求由数据层(Model)驱动,View来渲染。
有个问题是数据层可能有各种各样的异常,比如打开文件失败、句柄失败等等,这些错误怎么传递给View或者Control以实现弹出不同的错误警告?
能想到的是枚举返回值和异常。直接在Model层或者Control层弹错误框是不是不太好?
谢谢
PS:也不完全针对PHP,感觉有数据层、UI层之分的软件都很类似
--
FROM 183.131.105.*
抛出异常呗。
【 在 heroes999 (heroes999) 的大作中提到: 】
: 一般来说要求由数据层(Model)驱动,View来渲染。
: 有个问题是数据层可能有各种各样的异常,比如打开文件失败、句柄失败等等,这些错误怎么传递给View或者Control以实现弹出不同的错误警告?
: 能想到的是枚举返回值和异常。直接在Model层或者Control层弹错误框是不是不太好?
: ...................
--
FROM 117.30.53.*
many possible reasons of failure is an indication of trying to do
too much inside one function.
and of course, if you split up each piece of work into its own function,
you'd get a verbose API. get the balance.
in the mvc scenario, I usually follow the principal "failure in a model
does not fail a control" --- a function return failure to its caller
only when it cannot reasonably recover. a controller, when returned
failure from a model, can choose to present an error view instead; and
it still succeeds as a control, in that it shows the error as expected.
views shall never fail, unless given invalid input. but that is programmer
fault --- caller of functions are responsible of providing valid input.
【 在 heroes999 (heroes999) 的大作中提到: 】
: 一般来说要求由数据层(Model)驱动,View来渲染。
: 有个问题是数据层可能有各种各样的异常,比如打开文件失败、句柄失败等等,这些错误怎么传递给View或者Control以实现弹出不同的错误警告?
: 能想到的是枚举返回值和异常。直接在Model层或者Control层弹错误框是不是不太好?
: ...................
--
FROM 180.173.119.*
I usually follow the principal "failure in a model
does not fail a control" -- It is a valuable suggestion, thanks
不过目前我主要纠结的就是control怎么获取足够的错误信息来弹出相应的error message。目前感觉只能通过枚举 或者 异常(多态)来通知control
【 在 XeCycle 的大作中提到: 】
: many possible reasons of failure is an indication of trying to do
: too much inside one function.
: and of course, if you split up each piece of work into its own function,
: ...................
--
FROM 123.157.71.*