简体   繁体   English

在另一个非Codeigniter项目中使用Codeigniter模型

[英]Using codeigniter Models in another non-codeigniter project

I have 2 projects accessing the same DB. 我有2个项目正在访问同一数据库。 One is with CodeIgniter, the other is a home made mvc framework. 一个是使用CodeIgniter,另一个是自制的mvc框架。 I'd like to use the same Model layer. 我想使用相同的模型层。

Is it possible to access Codeigniter Models from another project? 是否可以从另一个项目访问Codeigniter模型?

我不确定您为什么要同时从两个不同的框架访问同一数据库(听起来像是灾难的配方),但是总的来说,我会说“不”。

What you actually want is not the model itself, You actually want the active records class located in /system/database/DB_active_rec, as that's the most common usage. 您真正想要的不是model本身,您实际上想要位于/ system / database / DB_active_rec中的活动记录类,因为这是最常见的用法。

That class extends CI_DB_driver 该类扩展了CI_DB_driver

This class accepts the config parameter for the DB(connection information). 此类接受用于DB(连接信息)的config参数。

You then want to extract the drivers themselves being used for the specific database you're working, the drivers can found at /system/database/drivers. 然后,您想提取用于您正在使用的特定数据库的驱动程序本身,这些驱动程序可以在/ system / database / drivers中找到。

CI->model simply loads the DB_active_rec , that's why you need to do $this->db->insert() CI->model只需加载DB_active_rec ,这就是为什么您需要执行$this->db->insert()

I've never did so myself, But I don't see any major dependencies in the files themselves. 我自己从来没有这样做过,但是我看不到文件本身有任何主要的依赖关系。 I might have missed something though 我可能已经错过了一些东西

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM