I'm using this class as Modal in my CodeIgniter project, as I'm newbie in CI, I wanna know if this has some issues, I'm using this modal for all queries, like I call this with parameters and it returns results as I wanted. But I'm not sure if it a good idea or it might give some bad impact to structure and security.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Crud extends CI_Model {
public function Read($TableName, $Condition) {
if ($Condition == '')
$Condition = ' 1';
$this->db->where($Condition);
$data = $this->db->get($TableName);
return $data->result();
}
public function Create($data, $TableName) {
if ($this->db->insert($data, $TableName))
return $this->db->insert_id();
else
return false;
}
public function Update($TableName, $Fields, $Condition) {
if ($Condition == '')
$Condition = ' 1';
$this->db->where($Condition);
if ($this->db->update($TableName, $Fields))
return true;
else
return false;
}
public function Delete($TableName, $Condition) {
if ($Condition == '')
$Condition = ' 1';
$this->db->where($Condition);
if ($this->db->delete($TableName))
return true;
else
return false;
}
public function Count($TableName, $Condition) {
if ($Condition == '')
$Condition = ' 1';
$this->db->where($Condition);
$result = $this->db->get($TableName);
if ($result)
return $result->num_rows();
else
return false;
}
I call this methods like this in my controller
public function changeStatus() {
$tableName = $this->uri->segment(4);
$status = $this->uri->segment(5);
$conditionId = $this->uri->segment(6);
$condition = " `id` = '$conditionId'";
$data = [
'is_active' => $status
];
if($this->Crud->Update($tableName, $data, $condition))
$this->session->set_flashdata('success', "Success! Changes saved");
else
$this->session->set_flashdata('danger', "Something went wrong");
$referer = basename($_SERVER['HTTP_REFERER']);
redirect('admin/seller/'.$referer);
}
Please let me know if I can provide more information