php - call a helper function in controller in codeigniter -
i created helper visit hits , contains function inserts data in database:
hits_counter_helper.php :
function count_hits($options = array()) { //determine whether user agent browsing site web browser, mobile device, or robot. if ($this->agent->is_browser()) { $agent = $this->agent->browser() . ' ' . $this->agent->version() . ' - ' . $this->agent->platform(); } elseif ($this->agent->is_robot()) { $agent = $this->agent->robot(); } elseif ($this->agent->is_mobile()) { $agent = $this->agent->mobile(); } else { $agent = 'unidentified user agent'; } //detect if user referred page if ($this->agent->is_referral()) { $referrer = $this->agent->referrer(); } // correcting date time difference adding 563 it. $date = date('y-m-j h:i:s', strtotime(date('y-m-j h:i:s')) + 563); $data = array ( 'page_address' => current_url(), 'user_ip' => $this->input->ip_address(), 'user_agent' => $agent, 'user_referrer' => $referrer, 'hit_date' => $date ); $this->db->insert('counter', $data); }
once auto loaded helper , called function in controller as:
my_controller.php:
public function index() { count_hits(); //index code here }
the problem getting blank page , other codes not run think. doing wrong?!
add following code beginning of helper function:
//get main codeigniter object $ci =& get_instance();
replace $this
$ci
in function.
and load helper function wherever want in controller this:
count_hits();
Comments
Post a Comment