zend framework 1.5.2 中实现梅花雪1.0树状菜单
開發(fā)平臺:Windows XP SP2
測試平臺:FreeBSD 7.0
開發(fā)工具:Netbeans 6.1
使用框架:Zend Framework 1.5.2
數(shù)據(jù)庫: MySQL 5.0.51a
**********************************
所需的數(shù)據(jù)庫表和ZF相關(guān)目錄以及文件:
一、表:(可以按MZ中的數(shù)據(jù)庫來設(shè)計(jì),視情況而定)
字段名????? 字段的具體說明
id?????????? 節(jié)點(diǎn)ID(不可為0,可以是數(shù)字或字符) parentId??? 本節(jié)點(diǎn)的父節(jié)點(diǎn)ID(若本節(jié)點(diǎn)已為根節(jié)點(diǎn),此處填0)
text??????? 節(jié)點(diǎn)的顯示文本(一般不允許為空,不過有一種情況例外,即根節(jié)點(diǎn),若根節(jié)點(diǎn)文本為空,這個(gè)根節(jié)點(diǎn)將不會在頁面里顯示)
hint??????? 節(jié)點(diǎn)的說明注解
icon??????? 節(jié)點(diǎn)的圖標(biāo),MzTreeView 1.0允許每個(gè)節(jié)點(diǎn)擁有不同的圖標(biāo)(對應(yīng)的名字在類里的icons和iconsExpand定義)
data?????? 節(jié)點(diǎn)掛的數(shù)據(jù),格式是 param=value¶m=value&... url里?后的那串字符串格式,
url???????? 每個(gè)節(jié)點(diǎn)允許擁有不同的鏈接,它為空或者為#時(shí),樹里這個(gè)節(jié)點(diǎn)的鏈接,點(diǎn)擊將無反應(yīng)
target????? 每個(gè)節(jié)點(diǎn)的鏈接允許在不同的target里打開,為空時(shí)取類里的默認(rèn)值
method??? 點(diǎn)擊該鏈接時(shí)所想觸發(fā)的腳本語句
特注:每個(gè)字段值中不可有冒號: 不可以換行 引號酌情考慮應(yīng)不與節(jié)點(diǎn)字符串的引號相沖突
我的為:
mysql> select * from module_tree;
+----+-----+----------+------+------+------+------+--------+--------+
| id | pid | text???? | hint | icon | data | url? | target | method |
+----+-----+----------+------+------+------+------+--------+--------+
|? 1 |?? 0 | aaa????? | aaaa | a??? | a??? | b??? | main?? |??????? |
|? 2 |?? 1 | computer | aaaa | a??? | a??? | b??? | main?? |??????? |
|? 3 |?? 1 | pet????? | aaaa | a??? | a??? | b??? | main?? |??????? |
|? 4 |?? 1 | ant????? | aaaa | a??? | a??? | b??? | main?? |??????? |
|? 5 |?? 2 | ketty??? | aaaa | a??? | a??? | b??? | main?? |??????? |
|? 6 |?? 2 | fav????? | aaaa | a??? | a??? | b??? | main?? |??????? |
|? 7 |?? 3 | pig????? | aaaa | a??? | a??? | b??? | main?? |??????? |
|? 8 |?? 3 | dog????? | aaaa | a??? | a??? | b??? | main?? |??????? |
|? 9 |?? 6 | cat????? | aaaa | a??? | a??? | b??? | main?? |??????? |
| 10 |?? 6 | apache?? | aaaa | a??? | a??? | b??? | main?? |??????? |
| 11 |?? 9 | tomcat?? | aaaa | a??? | a??? | b??? | main?? |??????? |
| 12 |? 10 | pet????? | aaaa | a??? | a??? | b??? | main?? |??????? |
| 13 |? 11 | vert???? | aaaa | a??? | a??? | b??? | main?? |??????? |
| 13 |? 11 | vert???? | aaaa | a??? | a??? | b??? | main?? |??????? |
+----+-----+----------+------+------+------+------+--------+--------+
二、目錄:
三、相關(guān)文件:
1.index.php //入口文件
2.TestDbCon.phhp //數(shù)據(jù)庫連接文件
3.ModuleTree //抽象出來的數(shù)據(jù)庫表文件
4.TestController.php //控制器
5.mz-tree.phtml //樹狀菜單生成頁面,包含mzTree.js對象,并根據(jù)服務(wù)器取回的數(shù)據(jù)生成的樹狀菜單。
相關(guān)文件內(nèi)容:
1.index.php //入口文件
1. <?php 2. 3. set_include_path('.' . PATH_SEPARATOR .'../library' . PATH_SEPARATOR . get_include_path() . PATH_SEPARATOR . '../application/modules/default/models' . PATH_SEPARATOR . '../application/modules/admin/models'); 4. 5. require_once 'Zend/Controller/Front.php'; 6. 7. require_once 'Zend/Controller/Router/Route.php'; 8. 9. 10. 11. $ctrl=Zend_Controller_Front::getInstance(); 12. 13. $ctrl->addModuleDirectory('../application/modules'); 14. 15. $ctrl->throwExceptions(true); 16. 17. $ctrl->dispatch(); 18. 19. ?> 2.TestDbCon.phhp //數(shù)據(jù)庫連接文件
?
1. <?php 2. 3. require_once 'Zend/Db.php'; 4. 5. require_once 'Zend/Registry.php'; 6. 7. 8. 9. class TestDbCon{ 10. 11. public static function getTestDbCon(){ 12. 13. $params=array( 14. 15. 'host'=>'localhost', 16. 17. 'username'=>'root', 18. 19. 'password'=>'123456', 20. 21. 'dbname'=>'test' 22. 23. ); 24. 25. $con=Zend_Db::factory('Pdo_Mysql',$params); 26. 27. return $con; 28. 29. } 30. 31. } 32. 33. ?> 3.ModuleTree //抽象出來的數(shù)據(jù)庫表文件
?
<?php/*** PHP Template.*/require_once 'Zend/Db/Table/Abstract.php';class ModuleTree extends Zend_Db_Table_Abstract{protected $_name='module_tree';protected $_primary='id';protected $_sequence=TRUE;}?>
?
4.TestController.php //控制器
<?phprequire_once 'Zend/Controller/Action.php';require_once 'Zend/View.php';require_once 'ModuleTree.php';require_once 'TestDbCon.php';class TestController extends Zend_Controller_Action{public function mzTreeAction(){$dbCon=DbCon::getDbCon();$mt_tb=new ModuleTree(array('db'=>$dbCon));$rowSet=$mt_tb->fetchAll();$this->view->rowSet = $rowSet;$this->render();} }?>
?
5.mz-tree.phtml //樹狀菜單生成頁面,包含mzTree.js對象,并根據(jù)服務(wù)器取回的數(shù)據(jù)生成的樹狀菜單。
<!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" lang="gb2312"><head><title>MzTree test</title> <script language="JavaScript" src="/public/scripts/MzTreeView10.js"></script></head><body><div ><script language="JavaScript">var tree = new MzTreeView("tree");tree.setIconPath("/public/images/"); //注意這里的路經(jīng)tree.icons["property"] = "property.gif";tree.icons["css"] = "collection.gif";tree.icons["book"] = "book.gif";tree.iconsExpand["book"] = "bookopen.gif"; //展開時(shí)對應(yīng)的圖片<?phpforeach ($this->rowSet as $row){echo "tree.nodes[/"" . $row->pid . "_" . $row->id . "/"] = /"text:" . $row->text . "; url:" . $row->url . "; target:" . $row->target . "/";";}?>tree.setURL("Catalog.asp");tree.setTarget("MzMain");document.write(tree.toString()); </script></div></body></head>
?
總結(jié)
以上是生活随笔為你收集整理的zend framework 1.5.2 中实现梅花雪1.0树状菜单的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 阿里云的oss bucket设置 404
- 下一篇: 菜鸟初学Echarts