CodeIgniter Framework中的库和模型有什么区别? [英] What is the difference between library and model in CodeIgniter Framework?

查看:63
本文介绍了CodeIgniter Framework中的库和模型有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是CI的新手。在我从事RoR和Symfony广泛工作之前。

I am new to CI. Before I had worked extensively in RoR and Symfony.

我不明白为什么CI确实提供了库和模型。我检查的大多数CI代码通常都将Library用作Model的包装器。模型专门保留用于与数据库对话。

I am unable to understand why exactly CI provides Library and Models. Most of the CI code I examined generally used Library as a Wrapper around Model. Models are exclusively kept for talking to database.

有人可以对此加以说明吗?

Can someone throw light on this ?

推荐答案

对此可能还有其他流派,但对我来说,如下:

There are probably other schools of thought on this, but for me it's as follows:

模型与应用程序紧密耦合,直接引用数据库模式/体系结构/文件路径等。

Models are tightly coupled to your application, making direct references to your DB schema/architecture/file paths etc.

图书馆是松散耦合的。它们应被视为第三方添加物,并且不应对您的应用或系统做任何假设。您应该能够以最少的配置随意插入库。确实,事实恰恰相反,您的库文件夹中的项目应该能够放入任何其他CI应用程序中。

Libraries are loosely coupled. They should be treated like 3rd party add-ons and should make no assumptions about your app or your system. You should be able to "drop in" libraries at will with a minimum amount of configuration. Indeed, the opposite should be true, items in your library folder should be able to be dropped into any other CI application.

这篇关于CodeIgniter Framework中的库和模型有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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