Display a tree dijit using zend framework

Posted by churris43 on Stack Overflow See other posts from Stack Overflow or by churris43
Published on 2010-04-02T12:09:12Z Indexed on 2010/04/02 12:13 UTC
Read the original article Hit count: 349

Filed under:
|
|

I am trying to display a tree of categories and subcategories by using dijits with zend framework. Haven't been able to find a good example. This is what I've got:

Basically I got the following code as my action:

class SubcategoriesController extends Zend_Controller_Action{
     .....
public function loadtreeAction()
{

Zend_Dojo::enableView($this->view);
Zend_Layout::getMvcInstance()->disableLayout();

//Creating a sample tree of categories and subcategories
$a["cat1"]["id"] = "id1";
$a["cat1"]["name"] = "Category1";
$a["cat1"]["type"] = "category";

$subcat1 = array("id" => "Subcat1","name" => "Subcategory1" , "type" => "subcategory");
$subcat2 = array("id" => "Subcat12","name" => "Subcategory12" , "type" => "subcategory");
$a["cat1"]["children"] = array($subcat1,$subcat2);

$treeObj = new Zend_Dojo_Data('id', $a);
$treeObj->setLabel('name');
$this->view->tree =  $treeObj->toJson();   
}
    ....
 }

And on my view:

<?php
    $this->dojo()->requireModule('dojo.data.ItemFileReadStore');
    $this->dojo()->requireModule('dijit.Tree');
    $this->dojo()->requireModule('dojo.parser');
?>

<div dojoType="dojo.data.ItemFileReadStore"  url="/Subcategories/loadtree" jsId="store"></div>
<div dojoType="dijit.tree.ForestStoreModel" jsId="treeModel" store="store" rootId="root" rootLabel="List of Categories" childrenAttrs="children" query="{type:'category'}"></div>
<div dojoType="dijit.Tree" model="treeModel" labelAttrs="ListOfCategories"></div>

It doesn't even seem to try to load the tree at all.

Any help is appreciated

© Stack Overflow or respective owner

Related posts about zend-framework

Related posts about dijit