CodeIgniter Forums

Full Version: call function from the same class
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]n1colius[/eluser]
I just begin my first project with CI, and i have a problem when i want to call a function within a class.

this is the my model class have code like this

Code:
<?php

class Model_admin_page extends Model {
    
    function Model_admin_page()
    {
        // Call the Model constructor
        parent::Model();
    }
    
    function getKategoriPage($parent,$level)
    {
        $sql = "SELECT catID,nama,parent FROM category_page WHERE catID<>'0' AND parent=? ORDER BY catID";
        $var_sql = array($parent);
        $query = $this->db->query($sql,$var_sql);
        
        $data = array();
        foreach ($query->result_array() as $q_data)
        {
            $q_data['level'] = $level;
            $data = $q_data;
            $b = $this->getKategoriPage($q_data['catID'],$level+1); //error in this line
            
            for($j=0;$j<count($b);$j++)
            {
                $data[] =  $b[$j];
            }
        }
        
        return $data;
    }
}
?&gt;

The problem is when i when to call a function within a same class, it gives me error
Message: Undefined offset: 0

any solution? Smile

El Forum

[eluser]n1colius[/eluser]
problem solved..actually there is an error in my code.. Big Grin

Code:
function getKategoriPage($parent,$level)
    {
        $sql = "SELECT catID,nama,parent FROM category_page WHERE catID<>'0' AND parent=? ORDER BY catID";
        $var_sql = array($parent);
        $query = $this->db->query($sql,$var_sql);
        
        $data = array();
        foreach ($query->result_array() as $q_data)
        {
            $q_data['level'] = $level;
            $data[] = $q_data; //$data should have bracket for array :D:D
            $b = $this->getKategoriPage($q_data['catID'],$level+1); //error in this line
            
            for($j=0;$j<count($b);$j++)
            {
                $data[] =  $b[$j];
            }
        }
        
        return $data;
    }