简体   繁体   English

Cake PHP将链接添加到树输出

[英]Cake PHP adding links to tree output

I am trying to add links to a Tree output list. 我试图将链接添加到树输出列表。

In addition to the links I get the &nbsp's included in the output 除了链接之外,输出中还包含&nbsp

So that it looks like this: 这样看起来像这样:

**My Categories
   Fun
      Sport
         Surfing
         Extreme knitting**

etc..... 等等.....

I don't want that obviously, but I do want to keep the nested output relationship. 我显然不希望这样做,但是我确实想保留嵌套的输出关系。

Below is code: 下面是代码:

Controller 控制者

<?php

class CategoriesController extends AppController {
 public $helpers = array('Html', 'Form');

    public function index() {

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

?>

View 视图

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

<?php echo $this->Html->link($data,
array('controller' => 'data', 'action' => 'view', $data)); ?>



</ul>
    <?php endforeach; ?>
    <?php unset($data); ?>

You should use a tree helper to output your tree as ul/li including links. 您应该使用树帮助程序将您的树输出为ul / li(包括链接)。 See http://www.dereuromark.de/2013/02/17/cakephp-and-tree-structures/ 参见http://www.dereuromark.de/2013/02/17/cakephp-and-tree-structures/

generateTreeList() - as documented - is a quick way to create a dropdown select ready list, not a tree. 如所记录的那样,generateTreeList()是创建下拉选择准备列表而不是树的快速方法。

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

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