我正在创建一个注册.每当我尝试将数据插入db时,都会引发此错误.
A PHP Error was encountered Severity: Notice Message: Undefined
property: insert_ctrl::$insert_model Filename:
controllers/insert_ctrl.php Line Number: 38
Fatal error: Call to a member function form_insert() on a non-object in
C:\xampp\htdocs\NewProject\application\controllers\insert_ctrl.php on
line 38
这是我的insert_ctrl.php
<?php
class insert_ctrl extends CI_Controller{
function _construct()
{
parent :: _construct();
$this->insert_model->form_insert($data);
}
function index()
{
//Including validation library
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class ="error">','</div>');
//Validating name field
$this->form_validation->set_rules('dname','Username','required|min_length[5]|max_length[15]');
$this->form_validation->set_rules('demail','Email','required|valid_email');
$this->form_validation->set_rules('dmobile','Mobile No.');
$this->form_validation->set_rules('daddress','Adress','required|min_length[10]|max_length[50]');
if($this->form_validation->run()==FALSE)
{
$this->load->view('insert_view');
}
else {
//Setting values for db table
$data=array(
'Student_Name'=>$this->input->post('dname'),
'Student_Email'=>$this->input->post('demail'),
'Student_Mobile'=>$this->input->post('dmoblie'),
'Student_Address'=>$this->input->post('daddress')
);
//Transfering data to model
$this->insert_model->form_insert($data);
//loading view
$this->load->view('insert_view');
}
}
}
//insert_model.php
<?php
class insert_model extends CI_Model{
function _construct()
{
parent :: _construct();
}
function form_insert($data)
{
$this->db->insert('student',$data);
}
}
?>
解决方法:
我的controller-insert_ctrl.php
class insert_ctrl extends CI_Controller{
function __construct()
{
parent :: __construct();
$this->load->model('insert_model');
}
function index()
{
$this->insert_model->form_insert();
echo "Clear";
}
}
我的模型insert_model.php
class insert_model extends CI_Model{
function __construct()
{
parent :: __construct();
}
function form_insert()
{
echo "model loaded Successfully";
}
}
该模型和控制器已完全按照您的名字命名.检查如何加载和调用模型.
您可以通过在php文件顶部添加以下代码行来克服内存限制错误.
ini_set(“memory_limit”,”512M”);