我是codeigniter的新手,我在构造函数方法中加载模型时遇到了一些问题。有人可以帮帮我吗?下面是我试图从...加载模型的控制器的代码。
<?php
class Login extends CI_Controller {
function Login(){
$this->load->model('membership_model');
}
public function index(){
$this->load->view('login_view.php');
}
public function authenticate(){
$user = $this->input->post('username');
$pass = sha1($this->input->post('password'));
if($user != null && $pass != null){
$access = $this->membership_model->request_access($user, $pass);
if($access == true){
$cookie = array(
'name' => 'username',
'value' => $user,
'expire' => '86500',
'domain' => 'unleashourmedia.com',
'path' => '/',
'prefix' => '',
'secure' => TRUE
);
$this->input->set_cookie($cookie);
echo "cookie";
} else {
redirect('login');
}
}
}
}
?>
答案 0 :(得分:1)
问题是你没有调用父类的构造函数。
将其添加为构造函数中的第一行:
parent::__construct();
答案 1 :(得分:0)
function Login(){
$this->load->model("membership_model","",TRUE);
}
答案 2 :(得分:0)
//make sure you call parent constructor before anything in that constructor like this
function Login(){
parent::__construct();
$this->load->model('membership_model');
}
//and you may also try to name the constructor __construct
function __construct(){
parent::__construct();
$this->load->model('membership_model');
}