控制器
function __construct()
{
parent::__construct();
$this->load->model("staffmodel","staff");
}
function index()
{
$data['staff'] = $this->staff->getAll();
$this->load->view("staff/index",$data);
}
function create()
{
if(@$_POST['create_staff'])
{
$data = $this->input->post('staff');
$this->staff->add($data);
$this->session->set_flashdata('message',"staff created successfully");
redirect("staff");
}
$this->load->view("staff/create");
}
function edit()
{
$id = $this->uri->segment(3);
$post = $this->staff->getById($id);
if(!$post)
{
redirect("staff");
}
if(@$_POST['update_staff'])
{
$postdata = $_POST['staff'];
$this->staff->update($postdata,$id);
$this->session->set_flashdata('message',"Staff updated successfully");
redirect("staff");
}
$data['staff'] = $post;
$this->load->view("staff/edit",$data);
}
function delete()
{
$id = $this->uri->segment(3);
$this->staff->delete($id);
$this->session->set_flashdata('message',"Staff deleted successfully");
redirect("staff");
}
模型
var $table = "staff";
function __construct()
{
parent::__construct();
}
function getAll()
{
$q = $this->db->get($this->table);
if($q->num_rows() > 0)
{
return $q->result();
}
return array();
}
function add($data)
{
$this->db->insert($this->table,$data);
}
function update($data,$id)
{
$this->db->where("id",$id);
$this->db->update($this->table,$data);
}
function delete($id)
{
$this->db->where("id",$id);
$this->db->delete($this->table);
}
function getById($id)
{
$this->db->where("id",$id);
$q = $this->db->get($this->table);
if($q->num_rows() > 0)
{
return $q->row();
}
return false;
}
我无法弄清楚这个错误表明了什么 .................................................. ............................................... 我无法找到解决此错误的方法请帮帮我
答案 0 :(得分:0)
更改此
$postdata = $_POST['staff'];
到这个
$postdata = $_POST;
它可能有用。由于您直接将staff
数组发布到该变量,因此默认情况下它将0
作为键。
答案 1 :(得分:0)
语法错误:删除第一行中的var
$table = "staff";