Сначала вы должны создать отдельное действие. Один для отображения, другой для загрузки:
public function indexAction()
{
Zend_Dojo::enableView($this->view);
$this->view->dojo()->setDjConfigOption('parseOnLoad', true);
}
public function loadtreeAction()
{
//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('ListOfCategories');
$this->view->tree = $treeObj->toJson();
}
И вы не должны забывать
setDjConfigOption('parseOnLoad', true)
В ваших views / scripts / index.phtml (если вы используете макет, некоторые части должны быть размещены, я позволю вам это сделать):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<?php
$this->dojo()->enable();
$this->dojo()->requireModule('dojo.data.ItemFileReadStore');
$this->dojo()->requireModule('dijit.Tree');
$this->dojo()->requireModule('dojo.parser');
echo $this->dojo();
echo $this->dojo()->addStylesheetModule('dijit.themes.tundra');
?>
</head>
<body class="tundra">
<div id="content">
<div dojoType="dojo.data.ItemFileReadStore" url="http://194.79.142.38:1080/rbplm/public/home/index/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>
</div>
</body>
</html>
А в loadtree.phtmln просто:
<?php echo $this->tree ?>