How does php obtain all subclass _ php Cache file writes under the category?

Source: Internet
Author: User
How does php obtain all subclass _ php Cache file writes under the category?

  1. Static function getMenuTree ($ arrCat, $ parent_id = 0, $ level = 0, $ all = True)
  2. {
  3. Static $ arrTree; // use static instead of global
  4. If (! $ All) $ arrTree = '';
  5. If (empty ($ arrCat) return FALSE;
  6. $ Level ++;
  7. If ($ level = 1) $ arrTree [] = $ parent_id;
  8. Foreach ($ arrCat as $ key => $ value)
  9. {
  10. If ($ value ['parent _ Cid'] = $ parent_id)
  11. {
  12. // $ Value ['level'] = $ level;
  13. $ ArrTree [] = $ value ['CID'];
  14. Unset ($ arrCat [$ key]); // deregister the data of the current node to reduce useless traversal
  15. Self: getMenuTree ($ arrCat, $ value ['CID'], $ level );
  16. } // Www.plcxue.com
  17. }
  18. Return $ arrTree;
  19. }

To use the preceding method, you need to write the classification to the php Cache file.

2. cache file writing method:

  1. Public function actionIndex2 ()
  2. {
  3. $ Filepath = Yii: getPathOfAlias ('application '). '/Data /';
  4. $ Arr = array ();
  5. $ Db = Yii: app ()-> db;
  6. $ Listinfo = $ db-> createCommand ("select name, cid, parent_cid, root_cid from item_cat_info")-> queryAll ();
  7. Foreach ($ listinfo as $ val)
  8. {
  9. $ Arr [$ val ['CID'] = array ('CID' => $ val ['CID'], 'name' => $ val ['name'], 'parent _ Cid' => $ val ['parent _ Cid'], 'root _ Cid' => $ val ['root _ Cid']);
  10. }
  11. $ Applist =" ";
  12. File_put_contents ($ filepath. 'itemcat. php', $ applist );
  13. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.