From d9bd9e62536458f9ab91540e08403b9543bd27a3 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Thu, 11 Apr 2013 12:20:05 -0400 Subject: [PATCH 1/3] Updated for 2.2 to avoid reliance on $this->data which is gone now. --- controllers/admin.php | 33 +++++++++++++++++++-------------- controllers/sample.php | 29 +++++++++++++---------------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/controllers/admin.php b/controllers/admin.php index 1c5fc21..687df54 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,9 @@ 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')) + ->build('admin/form'); } public function delete($id = 0) diff --git a/controllers/sample.php b/controllers/sample.php index d07b932..1b4163f 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', $data); } } \ No newline at end of file From bc89e602a6b027684efde2b6ca227fc3df2d688e Mon Sep 17 00:00:00 2001 From: jensdeschrijver Date: Sun, 5 May 2013 16:04:31 +0300 Subject: [PATCH 2/3] update set_value for name and slug Updated set_value('name', $name) and set_value('slug', $slug) to set_value('name', $sample->name) and set_value('slug', $sample->slug). Otherwise the variables give a PHP error. --- views/admin/form.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 @@ @@ -29,4 +29,4 @@ - \ No newline at end of file + From 155d2f51943fec523cee0aee0184ac47db9ec12e Mon Sep 17 00:00:00 2001 From: Tanel Tammik Date: Fri, 15 Nov 2013 10:19:36 +0200 Subject: [PATCH 3/3] fixing several bugs --- controllers/admin.php | 1 + controllers/sample.php | 2 +- views/admin/form.php | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/controllers/admin.php b/controllers/admin.php index 687df54..5e4d3e3 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -122,6 +122,7 @@ public function edit($id = 0) // Build the view using sample/views/admin/form.php $this->template ->title($this->module_details['name'], lang('sample.edit')) + ->set('sample', $sample) ->build('admin/form'); } diff --git a/controllers/sample.php b/controllers/sample.php index 1b4163f..79eff1f 100644 --- a/controllers/sample.php +++ b/controllers/sample.php @@ -45,6 +45,6 @@ public function index($offset = 0) ->set('items', $items) ->set('items_exist', $items_exist) ->set('pagination', $pagination) - ->build('index', $data); + ->build('index'); } } \ No newline at end of file diff --git a/views/admin/form.php b/views/admin/form.php index 89ef276..b91c177 100644 --- a/views/admin/form.php +++ b/views/admin/form.php @@ -12,12 +12,12 @@
  • -
    +
    name), 'class="width-15"'); ?>
  • -
    +
    slug), 'class="width-15"'); ?>