我遇到的问题不确定如何使用模型,视图和控制器进行设置。我是codigniter的新手,有点失去了学习。我在控制器中设置了一切,我知道现在是错误的,当我点击提交后插入一条记录时,页面出现页面无法显示。当它应该只是将我重定向到我插入记录。如何设置此数据以使用视图和模型
员工控制器
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Employee extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('employee_model');
}
//Insert the employee
public function insert_employee()
{
$data=array('name'=>$this->input->post('name'),
'LanId'=>$this->input->post('LanId'),
'reason'=>$this->input->post('reason'),
'PepNumber'=>$this->input->post('PepNumber'),
'Employee_Number'=>$this->input->post('Employee_Number'),
'department'=>$this->input->post('department'),
'status'=>1);
//print_r($data);
$result=$this->employee_model->insert_employee($data);
if($result==true)
{
$this->session->set_flashdata('msg',"Employee Records Added Successfully");
redirect('employee/index');
}
else
{
$this->session->set_flashdata('msg1',"Employee Records Added Failed");
redirect('employee/index');
}
}
员工模型
<?php
class Employee_model extends CI_Model
{
public function insert_employee($data)
{
$this->db->insert('employee_list',$data);
return ($this->db->affected_rows() != 1) ? false:true;
}
public function get_employee()
{
$this->db->select('*');
$this->db->from('employee_list');
$this->db->where('status',1);
$query =$this->db->get();
return $query->result();
}
public function delete_employee($id,$data)
{
$this->db->where('id',$id);
$this->db->update('employee_list',$data);
return ($this->db->affected_rows() != 1) ? false:true;
}
public function edit_employee($id)
{
$this->db->select('*');
$this->db->from('employee_list');
$this->db->where('id',$id);
$this->db->where('status',1);
$query =$this->db->get();
return $query->result();
}
public function update_employee($data,$id)
{
$this->db->where('id',$id);
$this->db->update('employee_list',$data);
return ($this->db->affected_rows() != 1) ? false:true;
}
}
除非你已经做了,在构造函数或自动加载,你必须在使用前加载模型:'$这个 - >负载>模型(“employee_model”);' – AdrienXL 2015-02-17 20:26:06