2010-03-12 81 views
0

我不知道我是否以正確的方式處理樹行爲,但我正在嘗試構建博客的評論系統。我想有一個5級深度的縮進。使用generatetreelist返回額外的字段

generatetreelist方法看起來像它是實現這一點的最快方法,但它看起來不像可以將字段添加到查詢中。我對嗎 ?有沒有辦法修改該方法?

謝謝

回答

0

如果是我,我會在結果集中執行此操作。當您在結果的第一維中獲得一個數值數組時,您可以在輸出數據時使用該數組來縮進或根據需要向評論中添加一個類。

+0

不知道我理解。你不會使用樹的行爲?或者只有文章有很多ArticleComment關係。 – Sabourinov 2010-03-12 18:38:54

2

這是我如何做類別。你可以相應地修改。

在控制器:

$categories = $this->Category->generatetreelist(null,null,null,"|-- "); 
    $categories_array = array(); 
    foreach($categories as $k => $v) 
    { 
     $categories_array[$k] = $this->Category->find('first', array('conditions' => array('Category.id' => $k))); 
     $categories_array[$k]["Category"]["path"] = $v; 
    } 

    $this->set(compact('categories','categories_array')); 

鑑於:

<table> 
    <thead> 
     <tr> 
     <th><?php __('Id');?></th> 
     <th><?php __('Name');?></th> 
     <th><?php __('Status');?></th> 
     <th><?php __('Action');?></th> 
    </tr> 
    </thead> 
    <tbody> 
    <?php 
    $i = 0; 
    foreach ($categories_array AS $categoryId => $category): 
    $class = 'even'; 
    if ($i++ % 2 == 0) { 
     $class = 'odd'; 
    }?> 
    <tr class="<?php echo $class;?>"> 
    <td><?php echo $category['Category']['id']; ?></td> 
    <td><?php echo $category["Category"]["path"];?></td> 


    <?php if ($category['Category']['status'] == '1'){ 
    $published = 'Active'; 
     }else { 
    $published = 'Inactive'; 
    } ?> 
<td><?php echo $published;?></td> 
<td> 
<?php echo $html->link($html->image("icons/16_icon_view.png"), array('action' => 'view', $category['Category']['id']), array('title'=>'View','escape' => false));?>&nbsp; 
      <?php echo $html->link($html->image("icons/16_icon_edit.png"), array('action' => 'edit', $category['Category']['id']), array('title'=>'Edit','escape' => false));?>&nbsp; 
      <?php echo $html->link($html->image("icons/16_icon_delete.png"), array('action' => 'delete', $category['Category']['id']), array('class'=>'delete_trigger','rel'=>'#error','title'=>'Delete','escape' => false));?> 
     </td> 
    </tr> 

    <?php endforeach; ?> 


</tbody> 
</table>