简体   繁体   English

如何在Cake PHP的视图中显示“树”数据

[英]How to display 'tree' data in the view in Cake PHP

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. 我正在做树教程 ,想在视图中显示数据并将其包装为html等。对于Cake PHP,我是新手,这有点麻烦。 Below is an example of what I've tried. 以下是我尝试过的示例。 In short, I figure I could assign the output to a variable using set. 简而言之,我认为我可以使用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); ?>

unlike other find methonds, generateTreeList doesen't return a named array but a plain array with numeric indexes 与其他查找方法不同, generateTreeList不会返回命名数组,而是返回带有数字索引的纯数组

try print_r($output) and you'll see how the array is formatted and how you can use it in your view 尝试print_r($output) ,您将看到数组的格式以及如何在视图中使用它

to show your data, in your foreach cicle you just have to do this 要显示您的数据,在您的foreach提示中,您只需要执行此操作

echo $data;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM