dongzhong5833 2016-08-30 06:53 采纳率: 0%
浏览 53
已采纳

如何将PHP CI模型函数拆分为多个“包含”文件

I have the following Code Igniter web service Model that my Controller calls. This Model has about 30 functions in it.

I would like to split up the functions in the Model to be in separate files so that it's easier for multiple people to work on them, although it's not possible to 'include' a file outside of a function like this:

class Webservice_model extends CI_Model{

    include 'function/login.php';
    include 'function/register.php';
    include 'function/checkin.php';

    // etc etc x 10
}

What is the correct way to do this? Without having to do this:

class Webservice_model extends CI_Model{

    function login(){
        // login functionality
    }
    function register(){
        // register functionality
    }
    function checkin(){
        // checkin functionality
    } 

    // etc etc x 10
}
  • 写回答

1条回答 默认 最新

  • dongzhao5970 2016-08-30 07:03
    关注

    The solution is create different models i.e. different files for each model

    example model 1: Login_model.php 2. Register_model.php 3. Checkin_model.php

    And then call them in model like

    class Webservice_model extends CI_model{
    function __construct()
    {
        parent::__construct();
        $CI =& get_instance();
        $CI->load->model('login_model');
        $CI->load->model('register_model');
        $CI->load->model('checkin_model');
    
    }
    

    }

    In this way different people can work on different functions

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大