How does php obtain all subclass _ php Cache file writes under the category?
- Static function getMenuTree ($ arrCat, $ parent_id = 0, $ level = 0, $ all = True)
- {
- Static $ arrTree; // use static instead of global
- If (! $ All) $ arrTree = '';
- If (empty ($ arrCat) return FALSE;
- $ Level ++;
- If ($ level = 1) $ arrTree [] = $ parent_id;
- Foreach ($ arrCat as $ key => $ value)
- {
- If ($ value ['parent _ Cid'] = $ parent_id)
- {
- // $ Value ['level'] = $ level;
- $ ArrTree [] = $ value ['CID'];
- Unset ($ arrCat [$ key]); // deregister the data of the current node to reduce useless traversal
- Self: getMenuTree ($ arrCat, $ value ['CID'], $ level );
- } // Www.plcxue.com
- }
- Return $ arrTree;
- }
To use the preceding method, you need to write the classification to the php Cache file.
2. cache file writing method:
- Public function actionIndex2 ()
- {
- $ Filepath = Yii: getPathOfAlias ('application '). '/Data /';
- $ Arr = array ();
- $ Db = Yii: app ()-> db;
- $ Listinfo = $ db-> createCommand ("select name, cid, parent_cid, root_cid from item_cat_info")-> queryAll ();
- Foreach ($ listinfo as $ val)
- {
- $ Arr [$ val ['CID'] = array ('CID' => $ val ['CID'], 'name' => $ val ['name'], 'parent _ Cid' => $ val ['parent _ Cid'], 'root _ Cid' => $ val ['root _ Cid']);
- }
- $ Applist =" ";
- File_put_contents ($ filepath. 'itemcat. php', $ applist );
- }
|