0

I am doing the tree tutorial and would like to display the data in a view and wrap it in html etc. I am new to Cake PHP and this has been a bit of a pain. Below is an example of what I've tried. In short, I figure I could assign the output to a variable using set. I am doing everything wrong.

Controller

<?php

class CategoriesController extends AppController {

    public function index() {

      $this->set('output', $this->Category->generateTreeList(null, null, null, '&nbsp;&nbsp;&nbsp;'));
    }
}

?>

View

   <?php foreach ($output as $data): ?>

        <div><?php echo $data['Category']['name']; ?></div>

    <?php endforeach; ?>
    <?php unset($data); ?>
4

1 回答 1

0

与其他查找方法不同,它不generateTreeList返回命名数组,而是返回带有数字索引的普通数组

尝试一下print_r($output),您将看到数组的格式以及如何在视图中使用它

要显示您的数据,在您的 foreach cicle 中您只需执行此操作

echo $data;
于 2013-10-04T07:02:55.477 回答