I want to make my code dry and I'm new to codeigniter I using $this->db->set($data) so I don't need to duplicate many of this set how cound I prevent $this->db->set($data) to skip in_image if it is empty to set it into db when update is it possible ?
My controller:
$data_arr=array(
'title'=>$this->input->post('txttitle'),
'desc'=>$this->input->post('txtdesc'),
'addr'=>$this->input->post('txtaddr'),
'fbn'=>$this->input->post('txtfbname'),
'fburl'=>$this->input->post('txturl'),
'status'=>$this->input->post('status')
);
if(!empty($_FILES['File']['tmp_name']))
{
$new_file_name=date("mdY")."_".time();
$config['upload_path'] = './assets/images/';
$config['allowed_types']= 'gif|jpg|png';
$config['max_size'] = 2048;
$config['max_width'] = 640;
$config['max_height'] = 420;
$config['file_name'] = $new_file_name;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('File'))
{
$error = array('error' => $this->upload->display_errors());
$image_arr = array('in_image'=>'error');
}
else
{
$image_arr = array('in_image'=>$this->upload->data('orig_name'));
}
}
else
{
$image_arr = array('in_image'=>'');
}
$data_merge = array_merge($data_arr,$image_arr);
$this->Description_model->update_all($data_merge,$id);
my model
public function update_all($data, $id)
{
if($data['in_image'] != 'error' && empty($data['in_image'])
{
/*
this is where i want to check if in_image is empty than prevent
$this->db->set($data) skip to set in_image
*/
$this->db->set($data)
->where('in_id',$id);
if($this->db->update('tbl_desc'))
{return TRUE;}
else
{return FALSE;}
}
elseif($data['in_image'] != 'error' && $data['in_image'] != ''))
{
}
else
{return FALSE;}
}
Thank in advance