php - How do i properly create a function in a helper file in codeigniter -


i trying learn code igniter , creating helper files. have functions_helper.php file located in applications/helpers folder:

<?php if ( ! defined('basepath')) exit('no direct script access allowed');  function __construct() {     parent::__construct();     $this->load->model('user','',true); } if (!function_exists('check_status')){  function check_status() { $ci = & get_instance();     $result=$ci->user->get_status(); //this line 14!!         if($result)     {         $status_array=array();         foreach($result $row)         {             $status_array=array(                 'source' => $row->status,                 'current' => $row->id                 );          if ($status_array['current'] == 1) {     $status_array['current'] = "live"; } else {     $status_array['current'] = "amazon down"; }              $ci->session->set_userdata('status',$status_array);         }         return true;       }     else     {          return false;     } } // end of check_status function }  

from can find, doing correctly, yet getting error:

php fatal error:  call member function get_status() on non-object in function_helper.php on line 14. doing wrong?  best way call function?  trying information returned db query. 

my get_status function is:

//function see status of amazon function get_status() {      $query = $this->db->query("select * amz active = 1");      if($query->num_rows()==1) {         return $query->row_array();     }else  {         return false;     } } //end of get_status function 

remove code

function __construct() {     parent::__construct();     $this->load->model('user','',true); } 

there no oo in helper files. not have class -__construct() used initialize classes.

then move

$this->load->model('user','',true); check_status function

$ci =& get_instance(); $ci->load->model('user','','true'); 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -