我为分页创建了 2 个控制器,为模型创建了 1 个控制器,为数据库创建了一个模型。和 2 个控制器扩展到其他控制器。像这样
class MY_Data extends CI_Controller{
public $layout;
public $xe_member;
public $member_srl;
public $is_logged_in = FALSE;
public $is_registerd = false;
public $director = array();
public $fighters = array();
public $logged;
function __construct(){
parent::__construct();
$this->load->model('member_login');
$this->load->model('db_log');
$this->layout = 'include/template';
}
function load_data(){
$this->xe_member = $this->member_login->member_check();
$this->member_srl = $this->xe_member['member_srl'];
$this->is_logged_in = $this->xe_member['is_logged'];
$this->is_registerd = $this->member_login->register_check
($this->member_srl);
if($this->is_registerd){
$this->director = $this->db->where('member_srl', $this->member_srl)->
limit(1)->get('fc_directors')->row();
$this->fighters = $this->db->where('member_srl', $this->member_srl)->
get('fc_fighters')->result();
}
}
}
登录
class Login extends MY_Data {
public function __construct()
{
parent::__construct();
$this->load->model('member_login');
}
public function index()
{
if (isset($_COOKIE['PHPSESSID'])) {
$data['PHPSESSID'] = $_COOKIE['PHPSESSID'];
}else {
$this->load->view('include/template', 'login_error');
die();
}
$this->load_data();
if($this->is_logged_in)
{
if ($this->is_registerd) {
$data['log'] = $this->db_log->read_all_log();
$data['main_contents'] = 'main/main';
$this->load->view('include/template', $data);
} else {
redirect('registration');
}
} else {
$data['main_contents'] = 'login_error';
$this->load->view('include/template', $data);
}
}
和主要
class Main extends MY_Data {
function __construct() {
parent::__construct();
}
function index(){
if(!$this->logged){
$data['main_contents'] = 'login/login_button';
$this->load->view($this->layout,$data);
}else {
$data['main_contents'] = 'main/main';
$this->load->view($this->layout,$data);
}
}
我知道这不是完美的代码,但是......我想在这里做的:
首先调用登录到 db_data 将在对象中提取数据库存储并主要获取对象来显示。但是在使用 main 时,我总是从母控制器那里得到空值。
我只是将控制器对象用于其他控制器。
我怎样才能做到这一点?