Skip to content

Instantly share code, notes, and snippets.

@ummahusla
Created April 1, 2015 10:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ummahusla/87f4716871210a94cd3e to your computer and use it in GitHub Desktop.
Save ummahusla/87f4716871210a94cd3e to your computer and use it in GitHub Desktop.
CodeIgniter CRUD
<!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>
<?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();
}
}
?>
<?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');
}
}
@tri82wiyono
Copy link

nice tutorial 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment