错误消息:调用未定义的方法 CI_DB_mysqli_result::results()

我是 CodeIgniter 的新手,在连接 db 后遇到以下错误。如果有人可以帮助我,那真是太好了。我检查了 StackOverflow 中以前的答案,但没有一个对我有帮助。


下面是控制器代码


    <?php


defined('BASEPATH') OR exit('No direct script access allowed');


class Welcome extends MY_Controller {


    public function index() {

        $this->load->view('home');

    }


    public function adminRegister() {

        //loading teh queries model 

        $this->load->model('queries');

        //Calling the getRoles function inside the roles

        $roles = $this->queries->getRoles();

        print_r($roles);

        exit();

        $this->load->view('register');

    }


    public function login() {

        echo 'login';

    }

}

型号代码


    <?php

//Details of queries whicha re used to interact with teh database


class Queries extends CI_Model {

//Created a function with the name getRoles  

    public function getRoles() {

        //Fetch the reocrds from the table

        $roles = $this->db->get('tbl_roles');

        if ($roles->num_rows() > 0) {

            return $roles->results();

        }

    }


}


?>

目前不使用来自控制器的数据。任何帮助将不胜感激。提前致谢。


至尊宝的传说
浏览 103回答 1
1回答

波斯汪

没有结果应该是结果参考CI 文档class Queries extends CI_Model {&nbsp; &nbsp; //Created a function with the name getRoles&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; public function getRoles() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Fetch the reocrds from the table&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $roles = $this->db->get('tbl_roles');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($roles->num_rows() > 0) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return $roles->result();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP