ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2019-10-31 22:33:07  阅读:283  来源: 互联网

标签:codeigniter php controller


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

从错误日志. 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都大写

标签:codeigniter,php,controller
来源: https://codeday.me/bug/20191031/1979045.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有