我遇到的問題不確定如何使用模型,視圖和控制器進行設置。我是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