消息:未定义属性:CI_DB_mysqli_driver :: $ student_model .............
我收到的错误是这样的:
<?php
class Student extends CI_Controller{
function __construct(){
parent::__construct();
}
public function index(){
echo "this is a index";
}
public function getall(){
$this->load->model('Student_model');
$data['query']=$this->db->student_model->student_getall;
$this->load->view('student_viewall',$data);
}
function get($id){
$this->load->model('student_model');
$data['query'] =$this->db->student_model->student_get($id);
$this->load->view('student_view',$data);
}
}
?>
答案 0 :(得分:2)
您的错误是错误地调用了模型:
而不是Type fooType = typeof(String);
if (fooType.IsAssignableFrom(typeof(int)))
{
Console.WriteLine("Will not show.");
}
if (fooType.IsAssignableFrom(typeof(string)))
{
Console.WriteLine("This will show.");
}
应该是
$data['query']=$this->db->student_model->student_getall;
然后在您的模型函数student_getall()中执行以下操作:
$data['query']=$this->student_model->student_getall();
最后,在您的视图中,您可以检索如下数据:
$query = $this->db->get('students');
$data=($query->num_rows() ) ?$query->result():false;
return $data;
答案 1 :(得分:0)
您正在调用学生模型的方式不正确。贝娄是你做的错误。我把它们变得大胆。
$this->Model_name->Method_name()
$data['query']=$this->db->student_model->student_getall;
在此声明中,我希望student_getall
是一种方法,应该像student_getall()
$data['query']=$this->Student_model->student_getall();
function __construct(){
parent::__construct();
}
public function index(){
echo "this is a index";
}
public function getall(){
$this->load->model('Student_model');
$data['query']=$this->Student_model->student_getall();
$this->load->view('student_viewall',$data);
}
function get($id){
$this->load->model('Student_model');
$data['query'] =$this->Student_model->student_get($id);
$this->load->view('student_view',$data);
}
}
?>
一样进行调用:label
有关模型的详细信息,请参阅此文档:https://www.codeigniter.com/user_guide/general/models.html class Student扩展CI_Controller {
input