Hi all I am having an error and I just can't see why codeigniter is throwing the error:
大家好,我有一个错误,我不明白为什么codeigniter会抛出错误:
controller:
控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Management extends CI_Controller {
public function index(){
//calls login page view
$this->managementView();
}
public function managementView(){
//loads course page view
$users['users'] = $this->management_model->getInfo();
$this->load->view("header");
$this->load->view("users", $users);
$this->load->view("footer");
}
}
Model:
模型:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Management_model extends CI_Model{
function getInfo(){
$query = $this->db->get("users");
$result = $query->result_array();
return $result;
}
}
I am receiving the following error, I just can't seem to see what the hell I'm doing wrong - I'm new to web stuff so don't know what these errors indicate:
我收到了下面的错误,我只是看不出我到底做错了什么——我是新手,所以不知道这些错误说明了什么:
Fatal error: Call to a member function getInfo() on a non-object
also see this:
还看到:
Severity: Notice
Message: Undefined property: Management::$management_model
Filename: controllers/management.php
Line Number: 12
I can't see the issue? - If anyone could point it out would be much appreciated.
我看不出这个问题?——如果有人能指出来,我们将不胜感激。
4 个解决方案
#1
1
you need to load the model before calling any function from the model. for eg:
您需要在调用模型的任何函数之前加载模型。如:
$this->load->model('management_model');
$users['users'] = $this->management_model->getInfo();
or you can load it via the constructor.
或者您可以通过构造函数加载它。
function __construct() {
parent::__construct();
$this->load->model('management_model');
}
}
the notice you are getting is clearly telling about the undefined property management model you can see more about this here
你得到的通知清楚地说明了未定义的物业管理模式你可以在这里看到更多。
#2
1
You dont appear to ever set the management_model property in your controller.
您似乎没有在控制器中设置management_model属性。
I would expect to see something like this somewhere in your controller:
我希望在你的控制器中看到这样的东西:
$this->management_model = new Management_model();
#3
0
Initially you can load the model like this
最初,您可以加载这样的模型。
$this->load->model('management_model');
then only u can use the object to call function
然后只有u可以使用对象调用函数。
you need some more clarity Click
你需要更清晰的点击。
#4
0
use
使用
$this->load->model('management_model');
before
之前
$users['users'] = $this->management_model->getInfo();
#1
1
you need to load the model before calling any function from the model. for eg:
您需要在调用模型的任何函数之前加载模型。如:
$this->load->model('management_model');
$users['users'] = $this->management_model->getInfo();
or you can load it via the constructor.
或者您可以通过构造函数加载它。
function __construct() {
parent::__construct();
$this->load->model('management_model');
}
}
the notice you are getting is clearly telling about the undefined property management model you can see more about this here
你得到的通知清楚地说明了未定义的物业管理模式你可以在这里看到更多。
#2
1
You dont appear to ever set the management_model property in your controller.
您似乎没有在控制器中设置management_model属性。
I would expect to see something like this somewhere in your controller:
我希望在你的控制器中看到这样的东西:
$this->management_model = new Management_model();
#3
0
Initially you can load the model like this
最初,您可以加载这样的模型。
$this->load->model('management_model');
then only u can use the object to call function
然后只有u可以使用对象调用函数。
you need some more clarity Click
你需要更清晰的点击。
#4
0
use
使用
$this->load->model('management_model');
before
之前
$users['users'] = $this->management_model->getInfo();