-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.php
84 lines (74 loc) · 3.66 KB
/
user.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
class User extends CI_controller {
function index()
{
$this->load->model('user_model');
$name = $this->user_model->all();
$data = array();
$data['name'] = $name;
$this->load->view('list',$data);
}
function create() {
$this->load->model('user_model');
$this->form_validation->set_rules('name','Name','required');
$this->form_validation->set_rules('description','Description','required');
$this->form_validation->set_rules('category','Category','required');
$this->form_validation->set_rules('author','Author','required');
$this->form_validation->set_rules('published','Published (date/time)');
$this->form_validation->set_rules('status','Status','required');
if($this->form_validation->run()==false)
{
$this->load->view('create');
} else {
// Save blog to database
$formArray = array();
$formArray['name']=$this->input->post('name');
$formArray['description']=$this->input->post('description');
$formArray['category']=$this->input->post('category');
$formArray['author']=$this->input->post('author');
$formArray['created_at']= date('Y-m-d');
$formArray['status']=$this->input->post('status');
$this->user_model->create($formArray);
$this->session->set_flashdata('success','Record added successfully');
redirect(base_url().'index.php/user/index');
}
}
function edit($Name)
{
$this->load->model('user_model');
$user=$this->user_model->getUser($Name);
$data=array();
$data['user']=$user;
$this->form_validation->set_rules('name','Name','required');
$this->form_validation->set_rules('description','Description','required');
$this->form_validation->set_rules('category','Category','required');
$this->form_validation->set_rules('author','Author','required');
$this->form_validation->set_rules('status','Status','required');
if($this->form_validation->run() == false) {
$this->load->view('edit',$data);
} else {
$formArray=array();
$formArray['name']=$this->input->post('name');
$formArray['description']=$this->input->post('description');
$formArray['category']=$this->input->post('category');
$formArray['author']=$this->input->post('author');
$formArray['status']=$this->input->post('status');
$this->user_model->updateUser($Name,$formArray);
$this->session->set_flashdata('success','Record updated successfully');
redirect(base_url().'index.php/user/index/');
}
}
function delete($Name)
{
$this->load->model('user_model');
$user=$this->user_model->getUser($Name);
if(empty($user)) {
$this->session->set_flashdata('failure','Record not found in database');
redirect(base_url().'index.php/user/index');
}
$this->user_model->deleteUser($Name);
$this->session->set_flashdata('success','Record deleted successfully');
redirect(base_url().'index.php/user/index');
}
}
?>