Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/nbproject/private/
3 changes: 3 additions & 0 deletions application/config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
| $autoload['libraries'] = array('database', 'session', 'xmlrpc');
*/



$autoload['libraries'] = array('database','session');


Expand All @@ -64,6 +66,7 @@
| $autoload['helper'] = array('url', 'file');
*/


$autoload['helper'] = array('url','form');


Expand Down
3 changes: 2 additions & 1 deletion application/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
| path to your installation.
|
*/
$config['base_url'] = 'http://localhost/trainning/';

$config['base_url'] = 'http://localhost/trainning/index.php';

/*
|--------------------------------------------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions application/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = '';
Expand Down
2 changes: 1 addition & 1 deletion application/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
|
*/

$route['default_controller'] = "welcome";
$route['default_controller'] = "category";
$route['404_override'] = '';


Expand Down
95 changes: 95 additions & 0 deletions application/controllers/category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Description of category
*
* @author pxthanh
*/
class Category extends CI_Controller {

//put your code here
private $_data = array();

public function __construct() {
parent::__construct();
$this->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");
}
}

}
55 changes: 55 additions & 0 deletions application/models/category_m.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Description of catelogy_m
*
* @author pxthanh
*/
class Category_m extends CI_Model{
//put your code here
public function __construct() {
parent::__construct();
}
private $_table='tbl_category';
public function getAll(){
$data = $this->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();
}
}
38 changes: 38 additions & 0 deletions application/views/category/Category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<html>
<head>
<title><?php echo $title;?></title>
</head>
<body>
<p> <?php
if(isset($status)) echo $status; ?>
</p>
<form action="<?php echo base_url('category'); ?>" id="frmSearch" method="post">
<label for="name">Search</label>
<input type="text" id="name" name="name"/>
<input type="submit" id="btnSearch" name="btnSearch" value="Search" >
</form>
<p><a href="<?php echo base_url()."category/create";?>">Create</a></p>
<table border="1">
<thead>
<tr>
<td> Id </td>
<td> name </td>
<td > Description </td>
<td> Action</td>
</tr>
</thead>
<tbody>
<?php foreach ($category as $item) { ?>
<tr>
<td> <?php echo $item->id; ?> </td>
<td> <?php echo $item->name; ?> </td>
<td ><?php echo $item->description; ?> </td>
<td><a href="<?php echo base_url()."category/edit/".$item->id;?>">Update</a>|
<a href="<?php echo base_url()."category/delete/".$item->id;?>">delete</a></td>
</tr>
<?php } ?>
</tbody>
</table>

</body>
</html>
23 changes: 23 additions & 0 deletions application/views/category/Create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<html>
<head>
<title>Create</title>
</head>
<body>
<div style="color: #ff3726;" >
<?php echo validation_errors(); ?>
</div>

<?php echo form_open(base_url()."category/create"); ?>

<h5>Name</h5>
<input type="text" name="name" value="" size="50" />

<h5>Description</h5>
<input type="text" name="des" value="" size="50" />

<div><input type="submit" value="Create" id="btnCreate" name="btnCreate" /></div>

</form>

</body>
</html>
23 changes: 23 additions & 0 deletions application/views/category/Update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<html>
<head>
<title>Update</title>
</head>
<body>
<div style="color: #ff3726;" >
<?php echo validation_errors(); ?>
</div>

<?php echo form_open(base_url()."category/edit/".$item->id); ?>

<h5>Name</h5>
<input type="text" name="name" value="<?php echo $item->name;?>" size="50" />

<h5>Description</h5>
<input type="text" name="des" value="<?php echo $item->description;?>" size="50" />
<div><input type="submit" value="Update" id="btnUpdate" name="btnUpdate" /></div>

</form>

</body>
</html>

7 changes: 7 additions & 0 deletions nbproject/project.properties
Original file line number Diff line number Diff line change
@@ -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=.
9 changes: 9 additions & 0 deletions nbproject/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.php.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/php-project/1">
<name>trainning</name>
</data>
</configuration>
</project>