php-调用未定义的方法UserModel :: addUser()

来自同一模型的其他功能运行良好,但我仅有两个功能有问题,它们都与数据库交互.在本地工作.

从错误日志. PHP致命错误:调用未定义方法UserModel :: getScreens()

我已经通过Google搜索了所有内容,但看不到这些功能无法在服务器上运行的原因.登录也可以访问数据库并且可以正常工作.

我为$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;
        }
    }
}

解决方法:

您不能在用户模型模型中使用多个大写字母.首字母必须大写,其他所有字母必须小写.

尝试:

Class Usermodel extends CI_Model{

在您的控制器中

$this->load->model('Usermodel', '', TRUE);
$this->Usermodel->getScreens()

将在一秒钟内发布文档

编辑:

http://codeigniter.com/user_guide/general/models.html

在“模型解剖”下查看规则.刚开始使用CI时,我花了太多时间尝试解决这个确切的问题:)

编辑2:

另外,我也很久以前也遇到过这个问题,但是$this-> usermodel-> whatever()可以在我的本地计算机上工作,但不能在服务器上工作.原因?对于大写字母,Apache感到很痛苦.确保在$this-> Usermodel中将所有U都大写

上一篇:PHP-Codeigniter活动记录从MySQL获取记录,其中ID等于数组中的ID


下一篇:PHP-从数组中的每个值中删除破折号,然后重建数组