2012-07-27 45 views
0

我一直在寻找在这个网站上的答案,并发现一些人问过同样的问题,但我还没有找到一个实际上说正确的解决方案。将主模型扩展到不同目录中的子模型

我想弄清楚如何让主模块保存某些变量值,以便我可以在其他模型中相应地访问它们。我在我的电脑上运行本地服务器,并且还使用模块插件。我也自动加载master_model。

问题是我收到一条错误消息,指出无法从users_model中找到master_model。

$autoload['model'] = array('msgboxes', 'metatags', 'genfunc', 'adverts', 'master_model'); 

<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 

/** 
* Master_model 
* 
* @author Jeff Davidson 
*/ 

class Master_model extends CI_Model 
{ 
    function __construct() 
    { 
     parent::__construct(); 
    } 

    var $users_table = 'users'; 
    var $user_profiles_table = 'user_profiles'; 
    var $user_login_sessions_table = 'user_login_sessions'; 
    var $user_statuses_table = 'user_statuses'; 
    var $user_roles_table = 'user_roles'; 

} 

/* End of file master_model.php */ 
/* Location: ./application/models/master_model.php */ 

<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 

/** 
* Users 
* 
* This model represents user authentication data. It operates the following tables: 
* - user account data, 
* - user profiles 
* 
* @package KOW Auth 
* @author Jeff Davidson 
*/ 

class Users_model extends Master_model 
{ 
    function __construct() 
    { 
     parent::__construct(); 
    } 


} 

/* End of file users_model.php */ 
/* Location: ./application/modules/users/models/users_model.php */ 

回答

0

你需要把Master_modelapplication/core目录和下面的代码添加到application/config/config.php文件:

function __autoload($class) 
{ 
    if(strpos($class, 'CI_') !== 0) 
    { 
     @include_once(APPPATH . 'core/'. $class . EXT); 
    } 
} 

更多here