CodeIgniter Forums

Full Version: How can I call custom made helper function in another custom made helper function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Blue Sapphire[/eluser]
Hi!
I have two custom made helper fucntions. How can I call one custom made helper fucntion in other custom made helper function. Code of two custom made helper functions is below:

Code:
function JEncode($arr){
    if (version_compare(PHP_VERSION,"5.2","<"))
    {    
        require_once("JSON.php");
          $this->json = new Services_JSON();//instantiate new json object

        $data=$this->json->encode($arr);  //encode the data in json format
    } else
    {
        $data = json_encode($arr);  //encode the data in json format
    }
    return $data;
  }


/***************************************************/
function mCountry(){
    
    $query = $this->db->query('select * from fa_country');
    
    if($query->num_rows() >0)
    {
        $nbrows = $query->num_rows();
        foreach($query->result() as $res){
            $rec['id']      = $res->id;
            $rec['iso']     = $res->iso;
            $rec['name']    = $res->name;
            $rec['iso3']    = $res->iso3;
            $rec['numcode'] = $res->numcode;
            $arr[] = $rec;            
    }
        $jsonresult = JEncode($arr);
        echo '({"total":"'.$nbrows.'","results":'.$jsonresult.'})';    
        //echo '({"total":"'.$nbrows.'","results":'.$jsonresult.'})';
}

I am calling function "JEncode" in second function "mCountry". Am I calling it correctly or not.

Thanks in advance

El Forum

[eluser]Blue Sapphire[/eluser]
Still waiting for some solution

El Forum

[eluser]Yash[/eluser]
You are accessing database in helper? I don't like this idea.

Helper should contain all functions in it which are related to each other.

Even if you want you can try creating super object I mean creating reference like thing.I've only idea so can't help much.