Not sure if it helps you at all but I once needed to know the ID of the current category in a tree structure where the 'token' of the category was the url param and not the id.
IE. http://server.com/categories/art/painting/van_gogh and I needed to resolve the id of the category 'van_gogh' in order to look up related records in other tables. I used this in my category model. function setCategory( $c = null ) { if( is_array( $c ) ) { $this->id = 1; if( count( $c ) > 0 ) { $d = array_values( $c ); $t = array_pop( $d ); $query = "SELECT parent_0.id FROM categories as parent_0 "; $where = "WHERE parent_0.token = '" . $t . "' "; $loop = 1; while( count( $d ) > 0 ) { $t = array_pop( $d ); $query = $query . "LEFT JOIN categories as parent_" . $loop . " ON parent_" . ($loop-1) . ".parent_id = parent_" . $loop . ".id "; $where = $where . "AND parent_" . $loop . ".token = '" . $t . "' "; $loop++; } $category_id = $this->query( $query . $where ); if( $category_id ) { $this->id = $category_id[0]['parent_0']['id']; } else { $this->id = -1; } } } } Where the category had id, token, created, modified, description, and parent_id fields. In my controller I look up the category params like so. function index( $path = null ) { $this->Category->setCategory( $function_args ); $this->set( 'category_data', $this->Category->findAll( "Category.id = $this->{Category->id}", null, null, 0 ) ); } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
