Welcome Guest, Not a member yet? Register   Sign In
How can I call custom made helper function in another custom made helper function
#1

[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
#2

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

[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.




Theme © iAndrew 2016 - Forum software by © MyBB