我正在使用CodeIgniter框架。 大多数模块都非常简单,它们只有SELECT * FROM TABLE和分页。 所以index()函数只有三行代码。 在这种情况下,在结构中包含模型的目的是什么。 我们是否使用强制模型来维护标准,还是可以根据该模块中总业务逻辑的简单性排除?
有时我需要从主迭代以外的三个表中获取数据。 我在一个控制器中以三个功能复制它。 希望这个我可以使用模型。
非常感谢您对此的建议和意见。 提前致谢。
I am using CodeIgniter framework. Most of the modules are very simple and they just have SELECT * FROM TABLE and a pagination. So the index() function would have just three lines of code. In this case, what is the purpose of including model in the structure. Do we use models compulsory to maintain standard or can we exclude according to the simplicity of the total business logic in that module?
Some times I need to fetch data from three tables other than the main iteration. and I am replicating this in three function in one controller. Hope for this I can use models.
I would appreciate your suggestions and comments on this. Thanks in advance.
最满意答案
没有人强迫你以这种方式实施。 MVC只是一种最佳实践。 您可以使用胖控制器,胖模型或根本不使用模型。 一段时间后,您将意识到模型/控制器分离的必要性,您可以在时机成熟时实现。
作为附注,我看到你正在使用像Select *这样的旧时尚查询。 您是否尝试过CI提供的有效记录?
http://codeigniter.com/user_guide/database/active_record.html
Nobody is forcing you to implement in this way. The MVC is just a best practice. You can use a fat controller, a fat model or no model at all. After a while you will realize the need for the model/controller separation and you can implement that when time comes.
As a side note I see you are using old fashion queries like Select *. Did you try the active record provided by CI ?
http://codeigniter.com/user_guide/database/active_record.html
更多推荐
发布评论