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

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

报告相同问题?

悬赏问题

  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan