PHP gets all the subclass methods below the classification

Source: Internet
Author: User
Tags yii



Get all the subclass methods below the taxonomy:

    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]); Unregisters the current node data, reducing the useless traversal                self::getmenutree ($arrCat, $value [' CID '], $level);            }        }        return $arrTree;    }

The premise of using this method is to write the classification to the cache file, the cache file is written as follows:

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 ' and ' = ' $val [' root_cid ']);        }        $applist = "<?php\nreturn". Var_export ($arr, true). "; N?> ";        File_put_contents ($filepath. ' itemcat.php ', $applist);    }


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.