CONTROLLER:
function read() {
echo(json_encode($this->news_model->read());
}
function update() {
$records = json_decode(stripslashes($this->input->get(‘models’)), true);
$this->news_model->update($records);
}
function destroy() {
$records = json_decode(stripslashes($this->input->get(‘models’)), true);
$this->news_model->destroy($records);
}
function create() {
$records = json_decode(stripslashes($this->input->get(‘models’)), true);
$this->news_model->create($records);
}
MODEL
function read() {
$this->db->select(“*”);
$query = $this->db->get(‘news’);
if($query->num_rows() > 0) {
$newsList = array();
foreach($query->result() as $news) {
$newsList[] = $news;
}
return($newsList);
}
}
function update($records) {
foreach($records as $r) {
$this->db->where(‘id’, $r['id']);
$this->db->update(‘news’, $r);
}
}
function destroy($records) {
foreach($records as $r) {
$this->db->where(‘id’, $r['id']);
$this->db->delete(‘news’);
}
}
function create($records) {
foreach($records as $r) {
$this->db->insert(‘news’, $r);
}
}