【发布时间】:2011-02-24 12:35:43
【问题描述】:
假设我有一个 Web 应用程序,对于一些数据库表,我想将它的数据作为数组/对象集合返回以显示在网页中,并作为 json 来构建一个 api。
我的问题是:我是否应该在我的模型中创建一个方法以将数据库中的数据作为 json 和其他方法以将数据作为数组返回,或者我应该只使用“getData”方法并在我的控制器?
案例 1:
型号:
function getDataFromDb(){
// query the db
// return as array/obj
}
function getDataAsJson(){
result = getDataFromDb();
// manipulate the result and return json object
}
案例 2
型号:
function getDataFromDb(){
// query the db
// return as array/obj
}
控制器
result = getDataFromDB();
// create json data from the returned result
【问题讨论】:
标签: model-view-controller model controller formats