本文介绍了codeigniter site_model严重性:注意错误此行有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是一个新手的codeigniter并试图学习crud在codeigniter .. > class Site extends CI_Controller
{
function index()
{
$ data = array();
if($ query = $ this-> site_model-> get_records())
{
$ data ['records'] =
}
$ this-> load-> view('options_view',$ data);
}
我的site_model是:
class Site_model extends CI_Model {
function __construct(){
parent :: __ construct
}
function get_records()
{
$ query = $ this-> db-> get('data');
return $ query-> result();
}
function add_record($ data)
{
$ this-> db-> insert('data',$ data);
return;
}
function update_record($ data)
{
$ this-> db-> where('id',12);
$ this-> db-> update('data',$ data);
}
function delete_row()
{
$ this-> db-> where('id',$ this-> uri-段(3));
$ this-> db-> delete('data');
}
}
'] = array('database');
当我尝试检查网站,我得到错误:
严重性:注意
pre>
消息:未定义属性:Site :: $ site_model
文件名:controllers / site.php
行号:9
此代码有什么问题?
解决方案模型:
class Site extends CI_Controller
{
//你还需要构造函数
function __construct(){
parent :: __ construct();
$ this-> load-> model('Site_model');
}
function index()
{
$ data = array();
//现在你可以使用
if($ query = $ this-> site_model-> get_records())
{
$ data ['records'] = $ query;
}
$ this-> load-> view('options_view',$ data);
}
I am a newbie with codeigniter and trying to learn crud in codeigniter..My site controller is :
class Site extends CI_Controller { function index() { $data = array(); if($query = $this->site_model->get_records()) { $data['records'] = $query; } $this->load->view('options_view', $data); }
And my site_model is :
class Site_model extends CI_Model { function __construct(){ parent::__construct(); } function get_records() { $query = $this->db->get('data'); return $query->result(); } function add_record($data) { $this->db->insert('data', $data); return; } function update_record($data) { $this->db->where('id', 12); $this->db->update('data', $data); } function delete_row() { $this->db->where('id', $this->uri->segment(3)); $this->db->delete('data'); } }
I made $autoload['libraries'] = array('database');When i try to check the site I get error :
Severity: Notice Message: Undefined property: Site::$site_model Filename: controllers/site.php Line Number: 9
What is wrong with this code?
解决方案Load the model:
class Site extends CI_Controller { //you also need the constructor function __construct(){ parent::__construct(); $this->load->model('Site_model'); } function index() { $data = array(); //now you can use it if($query = $this->site_model->get_records()) { $data['records'] = $query; } $this->load->view('options_view', $data); }
这篇关于codeigniter site_model严重性:注意错误此行有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!