Skip to content

Instantly share code, notes, and snippets.

@aslamdoctor
Created August 19, 2017 03:42
Show Gist options
  • Save aslamdoctor/4243ee247f391f4da022bd348e14c962 to your computer and use it in GitHub Desktop.
Save aslamdoctor/4243ee247f391f4da022bd348e14c962 to your computer and use it in GitHub Desktop.
Boilerplate code for HMVC Controller file
<?php if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
class Perfectcontroller extends MX_Controller
{
function __construct()
{
parent::__construct();
}
function get($order_by)
{
$this->load->model('mdl_perfectcontroller');
$query = $this->mdl_perfectcontroller->get($order_by);
return $query;
}
function get_with_limit($limit, $offset, $order_by)
{
$this->load->model('mdl_perfectcontroller');
$query = $this->mdl_perfectcontroller->get_with_limit($limit, $offset, $order_by);
return $query;
}
function get_where($id)
{
$this->load->model('mdl_perfectcontroller');
$query = $this->mdl_perfectcontroller->get_where($id);
return $query;
}
function get_where_custom($col, $value)
{
$this->load->model('mdl_perfectcontroller');
$query = $this->mdl_perfectcontroller->get_where_custom($col, $value);
return $query;
}
function _insert($data)
{
$this->load->model('mdl_perfectcontroller');
$this->mdl_perfectcontroller->_insert($data);
}
function _update($id, $data)
{
$this->load->model('mdl_perfectcontroller');
$this->mdl_perfectcontroller->_update($id, $data);
}
function _delete($id)
{
$this->load->model('mdl_perfectcontroller');
$this->mdl_perfectcontroller->_delete($id);
}
function count_where($column, $value)
{
$this->load->model('mdl_perfectcontroller');
$count = $this->mdl_perfectcontroller->count_where($column, $value);
return $count;
}
function get_max()
{
$this->load->model('mdl_perfectcontroller');
$max_id = $this->mdl_perfectcontroller->get_max();
return $max_id;
}
function _custom_query($mysql_query)
{
$this->load->model('mdl_perfectcontroller');
$query = $this->mdl_perfectcontroller->_custom_query($mysql_query);
return $query;
}
}
@Nicobonilla
Copy link

Should I chage mdl_perfectcontroller for mdl_perfectmodel of tihis code?

@aslamdoctor
Copy link
Author

Ah.. this is pretty old code. I took it from a youtube tutorial by David Connoly.
Try this repo https://github.com/aslamdoctor/ciboilerplate
You will find much better codeigniter setup.

@aslamdoctor
Copy link
Author

aslamdoctor commented Mar 3, 2020

Here is what you were talking about I guess :)
https://github.com/aslamdoctor/ciboilerplate/blob/master/application/core/MY_Model.php

You can even create REST APIs very easily using this repo.

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