diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..14bc68c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/nbproject/private/ \ No newline at end of file diff --git a/application/config/autoload.php b/application/config/autoload.php index 10bfffb..5f587fb 100644 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -52,6 +52,8 @@ | $autoload['libraries'] = array('database', 'session', 'xmlrpc'); */ + + $autoload['libraries'] = array('database','session'); @@ -64,6 +66,7 @@ | $autoload['helper'] = array('url', 'file'); */ + $autoload['helper'] = array('url','form'); diff --git a/application/config/config.php b/application/config/config.php index 2dd55a4..8b5151c 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -14,7 +14,8 @@ | path to your installation. | */ -$config['base_url'] = 'http://localhost/trainning/'; + +$config['base_url'] = 'http://localhost/trainning/index.php'; /* |-------------------------------------------------------------------------- diff --git a/application/config/database.php b/application/config/database.php index af7fcf3..000af98 100644 --- a/application/config/database.php +++ b/application/config/database.php @@ -48,9 +48,10 @@ $active_group = 'default'; $active_record = TRUE; -$db['default']['hostname'] = 'localhost'; -$db['default']['username'] = 'root'; -$db['default']['password'] = '123456'; + +$db['default']['hostname'] = '192.168.1.92'; +$db['default']['username'] = 'trainner'; +$db['default']['password'] = '1234@'; $db['default']['database'] = 'trainning'; $db['default']['dbdriver'] = 'mysql'; $db['default']['dbprefix'] = ''; diff --git a/application/config/routes.php b/application/config/routes.php index 5f9a583..d708d7e 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -38,7 +38,7 @@ | */ -$route['default_controller'] = "welcome"; +$route['default_controller'] = "category"; $route['404_override'] = ''; diff --git a/application/controllers/category.php b/application/controllers/category.php new file mode 100644 index 0000000..b286f46 --- /dev/null +++ b/application/controllers/category.php @@ -0,0 +1,95 @@ +load->model('category_m'); + $this->load->library('form_validation'); + } + + public function index() { + if ($this->input->post("btnSearch") != "") { + $name = $this->input->post("name"); + $this->_data['title'] = "Result search"; + $this->_data['category'] = $this->category_m->searchName($name); + } else { + $this->_data['title'] = "List Category"; + $this->_data['category'] = $this->category_m->getAll(); + } + $this->load->view('category/Category', $this->_data); + } + + public function create() { + $config = array( + array( + 'field' => 'name', + 'label' => 'name', + 'rules' => 'required|is_unique[tbl_category.name]' + ) + ); + if ($this->input->post('btnCreate') != "") { + $this->form_validation->set_rules($config); + if ($this->form_validation->run() != FALSE) { + $this->_data['status'] = ""; + $arr = array( + 'name' => $this->input->post('name'), + 'description' => $this->input->post('des'), + ); + if ($this->category_m->insert($arr)) { + $this->_data['status'] = "create successs"; + redirect(base_url(), $this->_data); + } + } + } + $this->load->view("category/Create", $this->_data); + } + + public function edit($id) { + $config = array( + array( + 'field' => 'name', + 'label' => 'name', + 'rules' => 'required' + ) + ); + if ($this->input->post('btnUpdate')) { + $this->form_validation->set_rules($config); + if ($this->form_validation->run() != FALSE) { + $arr = array( + 'name' => $this->input->post('name'), + 'description' => $this->input->post('des'), + ); + if ($this->category_m->update($arr, $id)) { + $this->_data['status'] = "Update successs"; + redirect(base_url(), $this->_data); + } + } + } + $this->_data['item'] = $this->category_m->getById($id); + $this->load->view('category/Update', $this->_data); + } + + public function delete($id) { + if ($this->category_m->delete($id)) { + redirect(base_url()); + } else { + redirect("error"); + } + } + +} diff --git a/application/models/category_m.php b/application/models/category_m.php new file mode 100644 index 0000000..95225f6 --- /dev/null +++ b/application/models/category_m.php @@ -0,0 +1,55 @@ +db->get($this->_table); + return $data->result(); + } + public function getById($id){ + return $this->db->where('id',$id) + ->get($this->_table) + ->row(); + + } + public function insert($data){ + return $this->db + ->insert($this->_table,$data); + } + public function update($arr,$id){ + return $this->db->where('id',$id) + ->update($this->_table,$arr); + } + public function delete($id){ + return $this->db + ->where('id', $id) + ->delete($this->_table); + } + public function searchName($name){ + return $this->db + ->like('name', $name) + ->get($this->_table) + ->result(); + } + public function getByName($name){ + return $this->db + ->where('name', $name) + ->get($this->_table) + ->row(); + } +} diff --git a/application/views/category/Category.php b/application/views/category/Category.php new file mode 100644 index 0000000..896445d --- /dev/null +++ b/application/views/category/Category.php @@ -0,0 +1,38 @@ + + + <?php echo $title;?> + + +

+

+
+ + + +
+

">Create

+ + + + + + + + + + + + + + + + + + + +
Id name Description Action
id; ?> name; ?> description; ?> id;?>">Update| + id;?>">delete
+ + + diff --git a/application/views/category/Create.php b/application/views/category/Create.php new file mode 100644 index 0000000..4b1e4f6 --- /dev/null +++ b/application/views/category/Create.php @@ -0,0 +1,23 @@ + + +Create + + +
+ +
+ + + +
Name
+ + +
Description
+ + +
+ + + + + diff --git a/application/views/category/Update.php b/application/views/category/Update.php new file mode 100644 index 0000000..07e0563 --- /dev/null +++ b/application/views/category/Update.php @@ -0,0 +1,23 @@ + + +Update + + +
+ +
+ +id); ?> + +
Name
+ + +
Description
+ +
+ + + + + + diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..024c098 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,7 @@ +include.path=${php.global.include.path} +php.version=PHP_53 +source.encoding=UTF-8 +src.dir=. +tags.asp=false +tags.short=false +web.root=. diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..019fdbc --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,9 @@ + + + org.netbeans.modules.php.project + + + trainning + + +