Created
April 1, 2015 10:33
-
-
Save ummahusla/87f4716871210a94cd3e to your computer and use it in GitHub Desktop.
CodeIgniter CRUD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Options View</title> | |
<!--[if lt IE 9]> | |
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> | |
<![endif]--> | |
</head> | |
<body> | |
<div> | |
<p>Create</p> | |
<?php echo form_open('site/create'); ?> | |
<label for="title">Title:</label><br /> | |
<input type="text" name="title" id="title" /><br /> | |
<label for="content">Content:</label><br /> | |
<input type="text" name="content" id="content" /><br /><br /> | |
<input type="submit" value="Submit" /> | |
<?php echo form_close(); ?> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Site extends CI_Controller { | |
function index() { | |
$this->load->view('options_view'); | |
} | |
function create() { | |
$data = array( | |
'title' => $this->input->post('title'), | |
'content' => $this->input->post('content') | |
); | |
$this->site_model->add_record($data); | |
$this->index(); | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Site_model extends CI_Model { | |
function get_records() { | |
$query = $this->db->get('ci_data2'); | |
return $query->result(); | |
} | |
function add_record() { | |
$this->db->insert('ci_data2', $data); | |
} | |
function update_record() { | |
$this->db->where('id', 14); | |
$this->db->update('ci_data2', $data); | |
} | |
function delete_row() { | |
$this->db->where('id', $this->uri->segment(3)); | |
$this->db->delete('ci_data2'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice tutorial 👍