The tp framework writes a method to obtain the return result of the top-level classification. The return result is null, which can be printed by the auxiliary functions. PHPcode uses id_category to obtain idfunctiongetParentInfo () {$ id_categoryTools: getValue (id_category). $ the ca tp framework writes a method to obtain the top-level category. return is null, results can be printed in helper functions.
PHP code
// Obtain the level-1 category id using id_category function getParentInfo () {$ id_category = Tools: getValue ('id _ category '); $ cate_info = $ this-> category_obj-> where ('id _ category = '. $ id_category)-> find (); // It is not a top-level if ($ cate_info ['pid']! = 0) {$ result = $ this-> getFirst ($ id_category);} else {$ result = $ cate_info;} dump ($ result ); // dump ('top-level class is :'. $ result ['id _ category ']. ':'. $ result ['name'].'
');} Function getFirst ($ id_category) {$ cate_info = $ this-> category_obj-> where ('id _ category = '. $ id_category)-> find (); echo $ this-> category_obj-> getLastSql ().'
'; If ($ cate_info ['pid']! = 0) {$ this-> getFirst ($ cate_info ['pid ']);} else {dump ($ cate_info); return $ cate_info ;}}
I used the classification id = 115 test result to print the expected result in getFirst, but the return $ cate_info is NULL when it is given to $ result.
Please give me some advice !!!
------ Solution --------------------
Function getFirst ($ id_category ){
$ Cate_info = $ this-> category_obj-> where ('id _ category = '. $ id_category)-> find ();
Echo $ this-> category_obj-> getLastSql ().'
';
If ($ cate_info ['pid']! = 0 ){
$ This-> getFirst ($ cate_info ['pid']); // the returned data is not caught here.
} Else {
Dump ($ cate_info );
Return $ cate_info;
}
}
------ Solution --------------------
PHP code
Function getFirst ($ id_category) {$ cate_info = $ this-> category_obj-> where ('id _ category = '. $ id_category)-> find (); echo $ this-> category_obj-> getLastSql ().'
'; If ($ cate_info ['pid']! = 0) {$ cate_info = $ this-> getFirst ($ cate_info ['pid ']);} return $ cate_info ;}
------ Solution --------------------
Return value is required!