Login Register

Using PHP 5.2.5 and MySQL 5 to populate a Dojo 1.1.0 Tree Widget

Hi Im working on this project for the company, and finally i found a decent tutorial, but by using the php5.2.5 and dojo 1.1.1 i can't seem to get this to work.
http://dojo.jot.com/WikiHome/Tutorials/Using%20PHP%20and%20MySQL%20to%20...
im like a newly born baby for AJAX/DOJO, took advanced java class in college and that's it.

DEMO
http://www.treetops-llc.com/etc/dojo/treedemo/eisleytree.html

so i know php5.2.0 and up is built in with json
however the tutorial's is not.. it's using the service_json.
i don't know how do i modified the code in treelisten.php

// instanciate a json-php instance
        require_once('JSON.php');
        $json = new services_JSON();
        
        if ( $action == "getChildren") {
               $jsonArray = $json->decode($data);
               $nodeArray = getChildren($jsonArray->node);
               print $json->encode($nodeArray);       
        }

also in elisley.html
i know dojo 1.1.0 has changed so the widget doesn't work in original tutorial so this doesn't work neither..

<script type="text/javascript">
dojo.require("dojo.widget.Button2");
dojo.require("dojo.event.*");
dojo.require("dojo.io.*");
dojo.require("dojo.widget.Tree");
dojo.require("dojo.widget.TreeNode");
dojo.require("dojo.widget.TreeSelector");
dojo.require("dojo.widget.TreeLoadingController");

can anybody help me?

Solved by go search google

Solved by go search google for dojotoolkit download and download dojo 0.4

:>

You can do it with dojo 1.1 as well

Just write your PHP to return the json in a format that can be used by a dojo.data store. Then all you have to do is write html like:

<div dojoType="dijit.layout.ContentPane" id="treeContainer">
<div dojoType="dojo.data.ItemFileReadStore"
        url="blocks/treeListen.php" jsid="treeStore">
</div>
<div dojoType="dojo.data.ItemFileReadStore"
     store="treeStore"
     labelAttr="category_name"
     jsId="Tree"
     persist=true
     onclick='treeOnClick'
     class='tundra'>

</div>
</div>

pointing the url to where you would get the json encoded data from (your php script).

Obviously you can build your json from what is in your mysql database.
My json built from php looks like:

/*{"identifier":"category_id",
   "label":"category_name",
   "items":[
     {"category_id":"1","parent_id":"0","category_name":"Payload","page_id":"-1","labelClass":"treeFolder",
         "children":[{"category_id":"114","parent_id":"1","category_name":"Analysis","page_id":"-1","labelClass":"treeFolder",
            "children":[{"category_id":"115","parent_id":"114","category_name":"CONF","page_id":"92","labelClass":"treeLeaf"},
                        {"category_id":"118","parent_id":"114","category_name":"CSB","page_id":"95","labelClass":"treeLeaf"},
                        {"category_id":"119","parent_id":"114","category_name":"Allocations","page_id":"96","labelClass":"treeLeaf"},
                        {"category_id":"120","parent_id":"114","category_name":"Box Allocations","page_id":"97","labelClass":"treeLeaf"},
                        {"category_id":"121","parent_id":"114","category_name":"Events Initiated","page_id":"98","labelClass":"treeLeaf"},
                        {"category_id":"122","parent_id":"114","category_name":"MRO","page_id":"99","labelClass":"treeLeaf"},
                        {"category_id":"116","parent_id":"114","category_name":"SV Integration","page_id":"93","labelClass":"treeLeaf"},
                        {"category_id":"117","parent_id":"114","category_name":"Resets","page_id":"94","labelClass":"treeLeaf"}
                      ]
             },
             {"category_id":"2","parent_id":"1","category_name":"Box","page_id":"-1","labelClass":"treeFolder",
               "children":[{"category_id":"57","parent_id":"2","category_name":"Data","page_id":"-1","labelClass":"treeFolder",
                 "children":[{"category_id":"11","parent_id":"57","category_name":"Analog","page_id":"1","labelClass":"treeLeaf"},
                          {"category_id":"12","parent_id":"57","category_name":"Digital","page_id":"2","labelClass":"treeLeaf"},
                          {"category_id":"13","parent_id":"57","category_name":"Discrete (Analogs)","page_id":"3","labelClass":"treeLeaf"},
                          {"category_id":"16","parent_id":"57","category_name":"Command Registers","page_id":"6","labelClass":"treeLeaf"},
                          {"category_id":"72","parent_id":"57","category_name":"SOH Frame Bytes 0 - 36","page_id":"51","labelClass":"treeLeaf"},
                          {"category_id":"73","parent_id":"57","category_name":"SOH Frame Bytes 37 - 100","page_id":"52","labelClass":"treeLeaf"},
                          {"category_id":"74","parent_id":"57","category_name":" SOH Frame Bytes 101 - 192","page_id":"53","labelClass":"treeLeaf"},
                          {"category_id":"83","parent_id":"57","category_name":" ASOH Frame","page_id":"62","labelClass":"treeLeaf"},
                          {"category_id":"84","parent_id":"57","category_name":"S2 Test Frame","page_id":"63","labelClass":"treeLeaf"},
                          {"category_id":"85","parent_id":"57","category_name":"RSOH Current Subframe","page_id":"64","labelClass":"treeLeaf"},
                          {"category_id":"92","parent_id":"57","category_name":"S2 GBD BDV Compatibility","page_id":"71","labelClass":"treeLeaf"}
                ]
               }
             ]
            }
         ]
      }
    ]
  } */
     

php looks like:
   $tree['identifier'] = 'category_id';
   $tree['label'] = 'category_name';

   /* add all the items, with children to the array */
   $tree['items'] = array('category_id'=>1,'parent_id'=>-1,'category_name'=>'Name','page_id'=>1,'labelClass'=>'class'
                    ,'children'=>array(.....));

Dave

example

Please can you give an example of php code which generate your JSON built form?

Thank's :-)