1. Во-первых, ваша модель должна использовать поведение «Tree» в файле модели (Modelname.php - в моем случае Post.php)
public $actsAs = array('Tree');
2. Далее вам нужно получить многопоточные результаты и передать их в представление (ModelnamesController.php - в моем случае PostsController.php).
$posts = $this->Post->find('threaded');
$this->set('posts', $posts);
3. Наконец, вот шаблон, который вы можете использовать, который отображает бесконечно многопоточный список для приведенных выше результатов
<div id="posts_navi">
<? function renderPosts($postsArray, $tmpModel){
//set return for the first time
if(!isset($return)){ $return = ""; }
$return .= '<ul>';
//create list
foreach ($postsArray as $post){
$return .= '<li>';
if($post['Post']['content'] != null){
$return .= $tmpModel->link($post['Post']['title'], array('action' => 'view', $post['Post']['id']),array('escape'=>false));
}else{
$return .= $post['Post']['title'];
}
//if post has children, go deeper
if(!empty($post['children'])){
$return .= renderPosts($post['children'], $tmpModel);
}
$return .= '</li>';
}
$return .= '</ul>';
return $return;
} ?>
<? $tmpModel = $this->Html; // we have to pass html helper inside, I am not sure it this is best way but it works
echo renderPosts($posts, $tmpModel); //finally, we render the $result returned. ?>
</div>