It looks like you're new here. If you want to get involved, click one of these buttons!
function on_after_post($values)
{
$CI =& get_instance();
$CI->load->library('image_lib');
$pk = $values['id'];
// create the thumbnail if an image is uploaded
if (!empty($CI->upload))
{
$data = $CI->upload->data();
if (!empty($data['full_path']))
{
// create thumb
$config = array();
$config['create_thumb'] = TRUE;
$config['source_image'] = $data['full_path'];
$config['width'] = 100;
$config['height'] = 80;
$config['master_dim'] = 'auto';
$config['maintain_ratio'] = TRUE;
$config['thumb_marker'] = '_thumb';
$CI->image_lib->clear();
$CI->image_lib->initialize($config);
if (!$CI->image_lib->resize())
{
$this->add_error($CI->image_lib->display_errors());
}
else // store thumb filename for convenience
{
$thm = $data['raw_name'] . $config['thumb_marker'] . $data['file_ext'];
$this->_update_thumb_field($pk, $thm);
}
}
}
return $values;
}
function _update_thumb_field($pk, $thm)
{
if(is_numeric($pk))
{
$this->db->set('thumbnail_file', $thm);
$this->db->set('id', $pk); /* without this, id gets set to 0 */
$this->db->where('id', $pk);
$this->db->update('photos');
}
}
Comments
function _update_thumb_field($pk, $thm) { if(is_numeric($pk)) { $where = 'id = '. $pk; $data = array('thumbnail_file' => $thm); $str = $this->db->update_string('photos', $data, $where); $this->db->query($str); $this->db->get('photos'); } }
So that avoided having to over-write the id using set(), which offended me beyond reasonable measure.
I'd like to know why the update method seems to railroad me into that situation though.
Still, the alternative is satisfactory.