Новости | FAQ | Авторы | Документация | В действии | Библиотека |
Инструменты | Полезные ссылки | Хостинги | Скачать | Примеры | Форум |
BeaVe 03.08.2005 13:05 / 03.08.2005 13:05
Вот так я поизвращался над вашим кодом о построении деревьев средствами P3:@categories_parents[params] $result[^table::sql{ SELECT category_id AS id, category_parent_id, category_type, category_thread, name, title, date_published, is_published FROM categories WHERE ^if(def $params.category_parent_id){category_parent_id = ^params.category_parent_id.int(0) AND} is_published = 1 ORDER BY date_published }[ ^if(^params.limit.int(0)){$.limit(^params.limit.int(0))} ]] @categories_threads[thread] $result[^table::sql{ SELECT category_id AS id, category_parent_id, category_type, category_thread, name, title, date_published, is_published FROM categories WHERE ^if($thread is table){ ^if($thread){category_thread IN (^thread.menu{$thread.category_thread}[,]) AND} }{ category_thread = ^thread.int(0) AND } is_published = 1 ORDER BY date_published DESC }] @category[category;body] $result[<category> <id>$category.id</id> <title>$category.title</title> <name>$category.name</name> $body </category>] @printCategoriesByParent[category_parent_id][levelcategories] ^if($categories_hash_tree.[$category_parent_id]){ $levelcategories[$categories_hash_tree.[$category_parent_id]] ^levelcategories.menu{ ^switch[$out]{ ^case[DEFAULT]{<category> <id>$levelcategories.fields.id</id> <title>$levelcategories.fields.title</title> <name>$levelcategories.fields.name</name> ^if($categories_hash_tree.[$levelcategories.id]){^printCategoriesByParent[$levelcategories.id]} </category>} } } } @categories_hash[categories;key] ^createTreeHash[$categories;$key] @categories_list[params] $root_categories[^categories_parents[]] $categories[^categories_threads[$root_categories]] $categories_hash_tree[^categories_hash[$categories;category_parent_id]] <categories> ^printCategoriesByParent[0] </categories>Из своих наблюдений.
@printCategoriesByParent[category_parent_id][levelcategories] ^if($categories_hash_tree.[0]){ $levelcategories[$categories_hash_tree.[0]] ^levelcategories.menu{ ^switch[$out]{ ^case[DEFAULT]{<category> <id>$levelcategories.fields.id</id> <title>$levelcategories.fields.title</title> <name>$levelcategories.fields.name</name> ^if($categories_hash_tree.[$levelcategories.id]){^printCategoriesByParent[$levelcategories.id]} </category>} } } }Ведь вызовом ^printCategoriesByParent[0] я и присваиваю этой переменной значение 0. А почему тогда Parser ругается?... ;-)