You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Could not use the model which the default controller has been created in the testcase #42
I want to reuse some model, so I wrote the code like this
<?php
/**
* 模型基础测试类
* 用于设置一些公共的自动加载功能
*/
abstract class CIModelTestCase extends CITestCase
{
protected $CI;
public function __construct()
{
parent::__construct();
}
public static function setUpBeforeClass()
{
$CI =& get_instance();
$CI->load->model('category');
$CI->load->model('flow_record');
$CI->load->model('order');
$CI->load->model('mall_m');
$CI->load->model('cart');
$CI->load->database();
}
public static function tearDownAfterClass()
{
$CI =& get_instance();
$CI->db->close();
}
}
But I found that some model were useless. When I hack the Loader.php in the function model():
foreach ($this->_ci_model_paths as $mod_path)
{
if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
{
continue;
}
require_once($mod_path.'models/'.$path.$model.'.php');
$this->_ci_models[] = $name;
$CI->$name = new $model();
// added this line
var_dump($name, new $model());
return $this;
}
The result:
Model ‘cart’, ‘order’, ‘mall_m’ were not in the ‘stubmodel’.
But if I change the default controller from
$route['default_controller'] = 'mall';
To
$route['default_controller'] = 'supermarket';
The result:
This time, the model ‘goods’ is not found in the ‘stubmodel’, but model ‘cart’, ‘order’, ‘mall_m’ were appeared.
How Should I fix it?
By the way:
Mall.php(only construct)
class Mall extends CI_Controller
{
public $data;
public $user;
function __construct()
{
//调用父类的构造函数
parent::__construct();
$this->load->helper('url');
$this->load->helper('cookie');
$this->load->library('session');
$this->load->model('cart');
$this->load->model('order');
$this->load->model("mall_m");//User_model模型类实例化对象
$user=$this->mall_m->user_selecet(array('username'=>$this->session->username,'password'=>$this->session->password));
}
}
Activity