thinkphp Get all sub-categories or parent category IDs

Source: Internet
Author: User

/** * @Author: HTL * @Email: [email protected] * @DateTime: 2016-04-22 11:25:02 * @Description: Get the current category  All Subclass ID * @pid: Parent class ID */function get_child_ids ($pid) {return $this->__get_ids ($pid, ' ', ' id ');}/** * @Author: HTL * @Email: [email protected] * @DateTime: 2016-04-22 11:25:02 * @Description: Gets all parent class ID * @id under the current classification: Subclass ID */FUNCT Ion Get_parent_ids ($id) {return $this->__get_ids ($id, ' ', ' pid ');}/** * @Author: HTL * @Email: [email&nbsp  ;p rotected] * @DateTime: 2016-04-22 11:25:02 * @Description: Gets all parent/child class IDs under Class * @pid: Multiple parent/subclass ID Set, delimited * @childids: Found Child/parent category list * @find_column: Where lookup field [Id|pid:default] */function __get_ids ($pid, $childids, $find _column = ' id ') {if (! $pid | | $pid &lt ; =0 | | strlen (PID) <=0 | |    !in_array ($find _column,array (' id ', ' pid '))) return 0;    if (! $childids | | strlen ($childids) <=0) $childids = $pid; $column = ($find _column = = ' id '? "pid": "id"),//ID and PID are mutually exclusive $ids = $this->model->where ("$column in ($pid)")->getfieLD ("$find _column", true);        $ids = Implode (",", $ids);    Not found, returns the IF ($ids <=0) return that has been found $childids;    Added to the collection $childids. = ', '. $ids; Recursive lookup return $this->__get_ids ($ids, $childids, $find _column);} /** * @Author: HTL * @Email: [email protected] * @DateTime: 2016-04-07 09:33:27 * @Description: Default state change */function Is_default () {$id = Intval ($_get[' id ')), $type = Intval ($_get[' status '), if ($id >0) {//cancels default if for all subcategories ($type!=1)    {$id = $this->_get_child_ids ($id);}    else{$id = $this->_get_parent_ids ($id); } print_r ($id); exit; $rst = $this->model->where ("ID in ($id)")->setfield (' Is_default ', $type); if ($rst) {$ This->success (L ("save_success"), U ("index")); else {$this->error (L (' save_error '));}} else {$this->error (L (' parameter_error '));}}

CREATE TABLE ' thk_material ' (    ' id ' int (one) not NULL auto_increment COMMENT ' self-increment id ',    ' pid ' int (one-by-one) NULL DEFAULT ' 0 ' COMMENT ' parent class ID '   );



From for notes (Wiz)



thinkphp Get all sub-categories or parent category IDs

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.