同じモデルの他の関数は正常に機能しています。問題が発生しているのはそのうちの2つだけで、どちらもデータベースと相互作用します。ローカルで動作します。
エラーログから。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);
..........
}
}
usermodel.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;
}
}
}