diff --git a/controllers/admin.php b/controllers/admin.php index 1c5fc21..5e4d3e3 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -48,9 +48,10 @@ public function index() $items = $this->sample_m->get_all(); // Build the view with sample/views/admin/items.php - $this->data->items =& $items; - $this->template->title($this->module_details['name']) - ->build('admin/items', $this->data); + $this->template + ->title($this->module_details['name']) + ->set('items', $items) + ->build('admin/items'); } public function create() @@ -59,10 +60,10 @@ public function create() $this->form_validation->set_rules($this->item_validation_rules); // check if the form validation passed - if($this->form_validation->run()) + if ($this->form_validation->run()) { // See if the model can create the record - if($this->sample_m->create($this->input->post())) + if ($this->sample_m->create($this->input->post())) { // All good... $this->session->set_flashdata('success', lang('sample.success')); @@ -76,32 +77,35 @@ public function create() } } - foreach ($this->item_validation_rules AS $rule) + $sample = new stdClass; + foreach ($this->item_validation_rules as $rule) { - $this->data->{$rule['field']} = $this->input->post($rule['field']); + $sample->{$rule['field']} = $this->input->post($rule['field']); } // Build the view using sample/views/admin/form.php - $this->template->title($this->module_details['name'], lang('sample.new_item')) - ->build('admin/form', $this->data); + $this->template + ->title($this->module_details['name'], lang('sample.new_item')) + ->set('sample', $sample) + ->build('admin/form'); } public function edit($id = 0) { - $this->data = $this->sample_m->get($id); + $sample = $this->sample_m->get($id); // Set the validation rules from the array above $this->form_validation->set_rules($this->item_validation_rules); // check if the form validation passed - if($this->form_validation->run()) + if ($this->form_validation->run()) { // get rid of the btnAction item that tells us which button was clicked. // If we don't unset it MY_Model will try to insert it unset($_POST['btnAction']); // See if the model can create the record - if($this->sample_m->update($id, $this->input->post())) + if ($this->sample_m->update($id, $this->input->post())) { // All good... $this->session->set_flashdata('success', lang('sample.success')); @@ -116,8 +120,10 @@ public function edit($id = 0) } // Build the view using sample/views/admin/form.php - $this->template->title($this->module_details['name'], lang('sample.edit')) - ->build('admin/form', $this->data); + $this->template + ->title($this->module_details['name'], lang('sample.edit')) + ->set('sample', $sample) + ->build('admin/form'); } public function delete($id = 0) diff --git a/controllers/sample.php b/controllers/sample.php index d07b932..79eff1f 100644 --- a/controllers/sample.php +++ b/controllers/sample.php @@ -9,7 +9,6 @@ */ class Sample extends Public_Controller { - public function __construct() { parent::__construct(); @@ -17,9 +16,10 @@ public function __construct() // Load the required classes $this->load->model('sample_m'); $this->lang->load('sample'); - - $this->template->append_css('module::sample.css') - ->append_js('module::sample.js'); + + $this->template + ->append_css('module::sample.css') + ->append_js('module::sample.js'); } /** @@ -30,24 +30,21 @@ public function index($offset = 0) // set the pagination limit $limit = 5; - $data->items = $this->sample_m->limit($limit) + $items = $this->sample_m->limit($limit) ->offset($offset) ->get_all(); // we'll do a quick check here so we can tell tags whether there is data or not - if (count($data->items)) - { - $data->items_exist = TRUE; - } - else - { - $data->items_exist = FALSE; - } + $items_exist = count($items) > 0; // we're using the pagination helper to do the pagination for us. Params are: (module/method, total count, limit, uri segment) - $data->pagination = create_pagination('sample', $this->sample_m->count_all(), $limit, 2); + $pagination = create_pagination('sample', $this->sample_m->count_all(), $limit, 2); - $this->template->title($this->module_details['name'], 'the rest of the page title') - ->build('index', $data); + $this->template + ->title($this->module_details['name'], 'the rest of the page title') + ->set('items', $items) + ->set('items_exist', $items_exist) + ->set('pagination', $pagination) + ->build('index'); } } \ No newline at end of file diff --git a/views/admin/form.php b/views/admin/form.php index 89ef276..a26f505 100644 --- a/views/admin/form.php +++ b/views/admin/form.php @@ -12,12 +12,12 @@