php - Multiple (unwanted) executions when passing parameter to controller -
i'm using codeigniter,
i have controller called 'property' action called 'details'
the function defining 'details' action takes 2 parameters:
so have url : example.com/property/details/23/appartment-for-rent
the first parameter id of record on db, 2nd parameter seo purposes
the details action increments views of record on db
problem :
when use http://example.com/property/details/23 works fine
when use seo link http://example.com/property/details/23/appartment-for-rent the script executes several times causes views count inaccurate. here controller/action function:
public function details($propertyid){ $this->load->model('model_property'); $pagedata['property'] = $this->model_property->getbyid($propertyid); if($pagedata['property']!=null){ $this->model_property->incrementviewbyid($pagedata['property']->id); $this->load->view('_common/header'); $this->load->view('_common/navigation'); $this->load->view('property/details',$pagedata); $this->load->view('_common/footer'); }else{ redirect(base_url().'error'); } }
here function increments views on model:
public function incrementviewbyid($id){ $this->db->where('id', $id); $this->db->set('views', 'views+1', false); $this->db->update('property'); }
Comments
Post a Comment