SilverRay SilverRay - 1 year ago 296
PHP Question

Codeigniter and jstree

I want to build tree view by using jstree and codeigniter and data is from mysql database but I don't know how. I read some tutorials and demos but it only makes me confuse. Is there an easy way to make the two work together without making the code unreadable?

Answer Source

I have found ways to create it easily and this is the code.

This is my controller code:

public function loadFabricTree()
    $data['fabric'] = $this->ModelDB->getFabricType();
    $nodes = array();

    foreach($data['fabric'] as $val)
    $nodes[] = ['id'=>$val['id'],'parent'=>"#",'text'=>$val['ItemDesc']];   

    echo json_encode($nodes);

This is my jquery code:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download