⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Peculiar problem with adding



Kobus Myburgh

Kobus Myburgh
  • profile picture
  • Member

Posted 01 November 2012 - 07:15 AM

Hi guys,

I have a strange problem with one of my controller functions. The only difference between a controller function that works correctly and one that doesn't, is that the one contains a file upload field, otherwise, the logic is the same.

When I use the File Upload one, the content gets added multiple times. Sometimes up to four times, with a single click of the save button.

Anyone seen this before?

Kind regards,

Kobus

victor

victor
  • profile picture
  • Member

Posted 01 November 2012 - 08:35 AM

Hi! Can you show your controller and callback functions?

Kobus Myburgh

Kobus Myburgh
  • profile picture
  • Member

Posted 22 November 2012 - 14:45 PM

Hi, sorry - I was expecting a notification when someone commented, and have not received one. I have now upgraded to GC version 1.3.3, and the problem still persists. Herewith the code:



function manage_images($inline = false, $redir = true)
{

// Cheat the CRUD editor. As the CRUD uses parameters to edit and delete items, it conflicts with the parameters we pass.
if ($inline == 'success' || $inline == 'add' || $inline == 'delete' || $inline == 'edit')
{
$inline = false;
}
if (has_access('Manage images'))
{
if ($redir)
{
has_access('Manage images', true);
}
$log = array(
'user' => $this->session->userdata('username'),
'severity' => 'High',
'action' => 'Manage images',
'msg' => sprintf($this->site_core_model->get_message('image_management_start'), $this->session->userdata('username')),
'type' => 'Notice'
);
l($log);
try
{
$crud = new grocery_CRUD();
$crud->set_table($this->config->item('db_prefix') . 'image');
$crud->set_subject('Linked Images');
$crud->callback_after_insert(array($this, 'log_insert_callback'));
$crud->callback_after_update(array($this, 'log_update_callback'));
$crud->display_as('title', 'Title')
->display_as('src', 'File name')
->display_as('active', 'Active?'); ;
$crud->unset_columns('createdate', 'moddate');
$crud->unset_fields('moddate', 'createdate');
$crud->set_field_upload('src', 'assets/uploads/images');
$data = $crud->render();
$temp['data'] = $data->output;
$temp['css_files'] = $data->css_files;
$temp['js_files'] = $data->js_files;
$temp['heading'] = 'Edit linked images';
$temp['contenttype'] = 'linked images';
$temp['load_files'] = $this->load_js($temp);
if (!$inline)
{
$this->template->load('template', 'admin_content/edit_content_crud', $temp);
}
else
{
$this->load->view('admin_content/edit_content_crud', $temp);
}
}
catch(Exception $e)
{
show_error($e->getMessage() . ' --- ' . $e->getTraceAsString());
}
}
else
{
$this->template->load('template', 'site_content/access_denied');
}
}


private function log_insert_callback()
{
$log = array(
'user' => $this->session->userdata('username'),
'severity' => 'High',
'action' => 'Content insert completed',
'msg' => sprintf($this->site_core_model->get_message('insert_completed'), $this->session->userdata('username')),
'type' => 'Notice'
);
l($log);
}

private function log_update_callback()
{
$log = array(
'user' => $this->session->userdata('username'),
'severity' => 'High',
'action' => 'Content update completed',
'msg' => sprintf($this->site_core_model->get_message('update_completed'), $this->session->userdata('username')),
'type' => 'Notice'
);
l($log);
}


The l() function is in a help, and simply calls the function to log what I did. It works for other editor instances, therefore I doubt this could cause any problems.

I did notice that the JS and CSS files do not load for GC, so I load them manually. Perhaps that is part of the problem? See function loadjs() below.


private function load_js($temp)
{
$out = "";
if (!empty($temp['css_files']))
{
foreach($temp['css_files'] as $file)
{
$out .= '<link type="text/css" rel="stylesheet" href="' . $file . '" />';
}
}
if (!empty($temp['js_files']))
{
foreach($temp['js_files'] as $file)
{
$out .= '<script src="' . $file . '"></script>';
}
}
return $out;
}

Kobus

Kobus
  • profile picture
  • Member

Posted 26 November 2012 - 06:45 AM

This problem still persists. Even with latest CI and latest GC. I don't understand. Any ideas? Thanks! :-)

Gloriamaris

Gloriamaris
  • profile picture
  • Member

Posted 24 February 2013 - 19:41 PM

Hi, I have the same problem, too. Have you solved this already? :\


Kobus

Kobus
  • profile picture
  • Member

Posted 28 February 2013 - 21:01 PM

Hi Gloriamaris,

 

I do not have the problem anymore, but I think it got solved after upgrading to 1.3.3 of GC. If that is not it, then it must've mysteriously gotten resolved. Hope this helps!

 

Kobus