-4
解釋MVC這是我model.But不知道如何插入database.Actually數據我是新來的CodeIgniter請告訴我數據插入一些簡單的例子,也許形式的數據插入。用最簡單的例子中插入笨數據和短
<?php
class News_model extends CI_Model {
public function __construct(){
$this->load->database();
}
public function get_news($slug = FALSE){
if ($slug === FALSE){
$query = $this->db->get('news');
return $query->result_array();
}
$query = $this->db->get_where('news', array('slug' => $slug));
return $query->row_array();
}
public function view($slug = NULL){
$data['news_item'] = $this->news_model->get_news($slug);
if (empty($data['news_item'])){
show_404();
}
$data['title'] = $data['news_item']['title'];
$this->load->view('templates/header', $data);
$this->load->view('news/view', $data);`enter code here`
$this->load->view('templates/footer');
}
}
您的混合控制器和模型嘗試閱讀手冊http://www.codeigniter.com/user_guide/ – JYoThI
u能請告訴我形式的任何簡單的例子,有兩個領域@此Jyothi –
你好請參考此鏈接http://www.phptutorials.club/crud-using-codeigniter-and-mysql/ – Shibon