如何在Codeigniter中使用另一个应用程序的模型 [英] How To Use Model Of Another Application in Codeigniter

查看:107
本文介绍了如何在Codeigniter中使用另一个应用程序的模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中创建两个托管在同一网站上的应用程序。
我的结构如下...

I am working on a project where I create Two Application hosted in same site. My structure is given below…

SITE



  • APPLICATION

    • font_end

    • back_end

    现在我的问题是,是否可以从另一个应用程序访问一个应用程序的模型。

    Now my question is,is it possible to access model of one application from another application.

    例如,在font_end应用程序中有一个名为User_model的模型。是否可以从back_end应用程序使用此模型。

    As example, I have a model named ‘User_model’ in font_end application. Is it possible to use this model from back_end application.

    谢谢。

    推荐答案

    是的,这是可能的,但有一个。无论你的文件在哪里是绝对的意义,但它不一定是世界上最容易完成的事情。

    Yes, it is possible, but there is a but. It doesn't matter where your files are in an absolute sense, but it is not necessarily the easiest thing in the world to accomplish.

    最好的办法是使用符号链接如果你可以并链接到你的模型目录的子目录。

    Your best bet is to use symlinks if you can and link them into a sub-directory of your models directory. This would be simple and clean.

    除此之外,您应该扩展Loader并覆盖& model 方法查看辅助目录(如果 $ path =='frontend'),可能会将$路径重新分配到备用应用程序的模型文件夹。

    Barring that, you should extend Loader and overwrite the &model method to look in the secondary directory (perhaps reassign $path to the alternate application's model folder if $path == 'frontend').

    如果这也不是一个选项,加载通过 APPPATH.'models /'.$路径完成。 '/'。$ model.EXT 。这意味着您可以通过 APPPATH.'models /'的相对路径访问模型。不要这样做,如果你可以避免它,但是。这是不明显的,并且是错误的邀请。

    If that also isn't an option, loading is done through APPPATH.'models/'.$path . '/' .$model.EXT. This means you can access the model by the relative path to APPPATH.'models/'. Don't do that if you can possibly avoid it, however. It is non-obvious and an invitation to errors.

    这篇关于如何在Codeigniter中使用另一个应用程序的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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