$ Category = D(' Category ')-& gt; Where ('category _ PID = 0')->; findAll();
//dump($ Category);
If (! Empty($Category)){ // Judge whether the first level is empty.
foreach($ Category as $ key = & gt; $value){ // loop reading
$ PID = $ value[' category _ id ']; //field assignment
$ Category[$ key][' child ']= D(' Category ')-& gt; Where ("category _ PID = $ PID")->; select();
//echo D(' Category ')-& gt; getLastSql(); //Writing method of printing sql statement
}
}
//dump($ Category);
$ this-& gt; assign('Category ',$ Category); //Mapping value