简体   繁体   English

如何在cakephp中对generateTreeList()方法的结果进行分页?

[英]how to paginate result of generateTreeList() method in cakephp?

i have a Categories table in my database that has lft, rght and parent_id columns for using Tree behavior in Cakephp. 我的数据库中有一个Categories表,其中有lft,rght和parent_id列,可用于在Cakephp中使用Tree行为。 the problem is how to paginate result of generateTreeList() method? 问题是如何对generateTreeList()方法的结果进行分页?

i can't use this : i want to paginate it 我不能使用此:我想分页

      $categories = $this->Category->generateTreeList(null,null,null,'_');
      $this->set('categories', $categories);

i also try to use thread type of find method, for retrieving data and use some recursive helper function like below for generating tree data 我也尝试使用find方法的线程类型来检索数据,并使用如下所示的一些递归帮助器函数来生成树数据

function CategoryRecTable($resultOfFindThread, $i = null) {
        $i = $i . '-';
        if (count($array)) {
            foreach ($resultOfFindThread as $vals) {
                echo "<tr>
                <td><font color=\"#CCCCCC\">" . $i . "</font>" . $vals['Category']['category'] . "</td>
                <td>" . 
                $this->Html->link('down' , array('admin' => false, 'controller' => 'categories', 'action' => 'movedown', $vals['Category']['id'])) . " - " . 
                $this->Html->link('up', array('admin' => false, 'controller' => 'categories', 'action' => 'moveup', $vals['Category']['id'])) . "</td>
                <td>Page</td>
                <td>" .  $vals['Category']['category'] . "</td>
                <td>" . $vals['Category']['id'] . "</td>
                <td>" . $this->Html->Link('Edit', array('controller' => 'ategories', 'action' => 'edit', $vals['Category']['id'])) . "</td>
                <td>" . $this->Html->Link(
                        'Delete',
                        array('admin' => true, 'action' => 'delete', $vals['Category']['id']),
                        array('confirm' => 'Are you sure?')) . "</td></tr>\n"; 
                if (count($vals['children'])) {
                    $this->CategoryRecTable($vals['children'], $i);
                }
                echo "\n";
            }
            echo "\n";
        }
    }

but also my problem exist, how to paginate this data in Cakephp. 但是还有我的问题,如何在Cakephp中对这些数据进行分页。 anybody can help me? 有人可以帮助我吗? thanks a lot 非常感谢

I'm not sure if this is possible as generateTreeList does not except parameters for LIMIT. 我不确定这是否可行,因为generateTreeList不会不包括LIMIT的参数。 There may be a way to hack it via extension of the Tree behaviour but this is not something I would recommend for usability and productivity purposes. 可以通过扩展Tree行为来破解它,但是出于可用性和生产力的目的,我不建议这样做。

Instead, I would use a library such as jsTree: http://www.jstree.com/ . 相反,我将使用jsTree之类的库: http : //www.jstree.com/

You can make similar performance gains that you'd receive from pagination by loading a sub-tree using ajax. 通过使用ajax加载子树,您可以从分页中获得类似的性能提升。 It's far more intuitive and will fit on one page. 它更加直观,可以放在一页上。

This style interface will also allow you to rearrange your category tree too. 此样式界面还允许您重新排列类别树。 For example, it will allow you to implement functionality move a sub-category up to a top-level category and vice-versa. 例如,它将允许您实现将子类别上移到顶级类别的功能,反之亦然。

This solution will be a lot easier to implement than hacking pagination on generate tree list. 与解决生成树列表中的分页相比,此解决方案的实现要容易得多。

put and order on lft field with 在LFT字段上订购

$this->Paginator->settings = array('order'=>'Category.lft');

and then you can use $this->Category->formatTreeList to change category names with spaced version. 然后,您可以使用$ this-> Category-> formatTreeList更改带有间隔版本的类别名称。

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

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