Our Controller: Site
<?php
class Site extends Controller {
function __construct()
{
parent::Controller();
$this->load->library('CRUD');
$this->load->model('site_model');
}
function _remap()
{
/* Using CRUD you can configure everything under _remap method
* http://codeigniter.com/user_guide/general/controllers.html#remapping
* this allow CRUD to take full control of your Controller
*/
// based on which model you want to refer to based on $this->load->model
$config['model'] = 'site_model';
// segment number to identify whether you want to use get, modify (and add) or remove
$config['segment'] = 2;
// segment number to identify the primary key of data or offset of pagination (during retrieve)
$config['segment_id'] = 3;
// configuration for data retrieving
$config['get'] = array (
'method' => 'get',
'base_url' => site_url('site/index'),
'limit' => 10,
'callback' => '_index'
);
// configuration for data update/create
$config['set'] = array (
'method' => 'update',
'prefix' => 'data',
'fields' => 'get_fields',
'data' => 'get_one',
'callback' => '_update'
);
// configuration for data remove
$config['remove'] = array (
'method' => 'remove',
'callback' => '_remove'
);
// compile everything using CRUD magic
$this->CRUD->initialize($config);
}
function _index($html)
{
$this->load->view('get', $html);
}
function _update($html)
{
$this->load->view('update', $html);
}
function _remove($response)
{
// Print out error
echo $response['error'];
}
}
/* End of file site.php */
/* Location: ./system/application/controllers/site.php */
If you have any question feel free to ask.



Recent Comments