Codeigniter: My controller is not able to access the model
//My controller section
<?php
class Myadmin extends CI_Controller
{
public function _construct()
{
parent::_construct();
$this->load->library('form_validation');
$this->load->helper('form');
$this->load->model('adder','',TRUE);
}
public function index()
{
echo " i am about to call the model";
$this->adder->insert_user();
}
}
?>
**//My model section**
<?php
class Adder extends CI_Model {
function_construct() {
parent::_construct();
}
public function insert_user()
{
echo " Hi开发者_运维知识库 ,the model is accessed";
}
}
?>
Is it because of "function_construct()"? It has no space and you should use two _
function _construct(){ parent::_construct(); } Same in Controller
The problem is the way you load the model in your controller.
In the current version of the CodeIgniter you should do something like this:
//loading the model
$this->load->model('adder', 'fubar');
//accessing it's functions
$this->fubar->function();
for more info see this.
EDIT:
You have defined a _construct()
function which must be __construct().
Also you should fix parent::_construct();
to parent::__construct()
.
精彩评论