0

hi

i am new to codigniter...
i fetch records from db and want to access it in another functio in same class but it giving me error.. any idea...

class Usercp_Task extends CI_Controller {
    var $cate=array();
    public function index() {
        $this->getCategoryDetails();
    }
    public fun getCategoryDetails()
    {
         $array_db=result form database...
         $this->$cate=$array_db;
    }
    public fun showcategory()
    {
         print_r($cate);
    }

thanx

Edited by mangel.murti: n/a

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by cereal
0

In CI you should use a model to do this kind of tasks, but you can pack the result to a string and return that, just use true as third parameter in $this->load->view :

$string = $this->load->view('my_view',$data,true);

A full example would be:

public function test()
{
    $data['a'] = 'hello world!';
    $string = $this->load->view('first_view',$data,true);
    return $string;
}
    
public function hello()
{
    $data['read'] = $this->test();
    $this->load->view('second_view',$data);
}

Bye :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.