[英]creating news item in codeigniter
i want to create news item in codeigniter with use slug but is error display like this. 我想使用slug在codeigniter中创建新闻项,但是这样的错误显示。
> Call to a member function insert() on a non-object in line 34
I am a newbie in Codeigniter and couldn't really figure out how to solve this. 我是Codeigniter的新手,无法真正解决该问题。
my controller 我的控制器
function tambah_profil()
{
$this->data['title'] ='create a new items';
$this->form_validation->set_rules('judul', 'Judul', 'required');
$this->form_validation->set_rules('content', 'Content', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->data['contents'] = $this->load->view('admin/profil/tambah_profil', '', true);
}else{
$this->mhalaman->insert_profil();
$this->data['contents'] = $this->load->view('admin/profil/view_profil', '', true);
}
$this->data['orang'] = $this->mlogin->dataPengguna($this->session->userdata('username'));
$this->data['contents'] = $this->load->view('admin/profil/tambah_profil', '', true);
//$this->data['contents'] = 'admin/profil/tambah_profil';
$this->load->view('template/wrapper/admin/wrapper_ukm',$this->data);
}
my model 我的模特
var $db;
private $tbl_halaman = 'halaman';
public function __construct()
{
parent ::__construct();
$this->load->database();
}
function get_profil($slug = FALSE)
{
if ($slug === FALSE)
{
$query = $this->db->get($this->tbl_halaman);
return $query->result_array();
}
$query = $this->db->get_where($this->tbl_halaman, array('slug'=>$slug));
return $query->row_array();
}
function insert_profil()
{
$slug = url_title($this->input->post('judul'),'dash', TRUE);
$data = array(
'judul' => $this->input->post('judul'),
'slug' => $slug,
'content' => $this->input->post('content')
);
return $this->db->insert($this->tbl_halaman ,$data); //line 34
}
please help me what to do. 请帮我该怎么办。 thank you. 谢谢。
Please check whether you have loaded $this->load->database() inside the model constructor. 请检查是否在模型构造函数中加载了$ this-> load-> database()。
$this->db->method_name(); $ this-> db-> method_name(); will only work when the database library is loaded. 仅在加载数据库库时有效。
If you plan to use the database throughout your application, I would suggest adding it to your autoload.php in /application/config/. 如果您打算在整个应用程序中使用该数据库,建议将其添加到/ application / config /中的autoload.php中。
$autoload['libraries']=array('database'); $ autoload ['libraries'] = array('database');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.