来自同一模型的其他功能工作正常,我只有其中两个有问题,它们都与数据库交互。在当地工作。
从错误日志中。PHP 致命错误:调用未定义的方法 UserModel::getScreens()
我已经通过谷歌搜索了所有内容,但看不到这些功能无法在服务器上运行的原因。登录也与数据库对话并且工作正常。
我已经为调用$this->UserModel->method()
$this->userModel->method()
等尝试了不同的命名约定。与更改加载模型相同。$this->load->model('UserModel', ' ', TRUE);
user.php(控制器)
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start();
class User extends CI_Controller {
function __construct(){
parent::__construct();
$this->load->model('usermodel','',TRUE);
}
public function register(){
..........
$addUser = $this->usermodel->addUser($this->input->post());
..........
}
public function screens($id = FALSE){
$data = $this->checkStatus('screens');
//userInfo is coming from the checkStatus function.
//Have verified with a var_dump($user_id) and it appears
$user_id = $data['userInfo'][0]['id'];
$data['screens'] = $this->Usermodel->getScreens($user_id);
if($data){
$data['title'] = 'My SCREENs';
if($id){
$data['id'] = $id;
$this->load->template('screenview', $data);
} else {
$this->load->template('screens', $data);
}
}
}
public function login(){
//This works
..........
$result = $this->usermodel->login($email, $password);
..........
}
}
用户模型.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class UserModel extends CI_Model{
function __construct(){
parent::__construct();
$this->salt = "_________";
}
function getScreens($userID){
//This doesn't work
$this -> db -> select('*');
$this -> db -> from('screens');
$this -> db -> where('user_id = ' . "'" . $userID . "'");
$query = $this -> db -> get();
return $query->result_array();
}
function addUser($data){
//This doesn't work
$data = array(
'first_name' => $data['firstname'] ,
'last_name' => $data['lastname'] ,
'email' => $data['email'],
'dob' => $data['dob-day'] . '/' . $data['dob-month'] . '/' . $data['dob-year'],
'height' => $data['height'],
'weight' => $data['weight'],
'password' => sha1($data['password1'] . $this->salt),
'gender' => $data['gender']
);
$added = $this->db->insert('users', $data);
if($added){
return true;
} else {
return false;
}
}
function login($email, $password){
//This works
$this -> db -> select('id, email, password');
$this -> db -> from('users');
$this -> db -> where('email = ' . "'" . $email . "'");
$this -> db -> where('password = ' . "'" . sha1($password . $this->salt) . "'");
$this -> db -> limit(1);
$query = $this -> db -> get();
if($query -> num_rows() == 1){
return $query->result();
} else {
return false;
}
}
}