php codeigniter为什么我们应该在控制器中有很少的业务登录时使用模型(php codeigniter why should we use models when there is very

编程入门 行业动态 更新时间:2024-10-20 18:52:59
php codeigniter为什么我们应该在控制器中有很少的业务登录时使用模型(php codeigniter why should we use models when there is very little business login in a controller)

我正在使用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

更多推荐

本文发布于:2023-08-05 20:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1439291.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中有   我们应该   控制器   模型   业务

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!