Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 如何在CakePHP中创建线程列表?_List_Cakephp_Multithreading - Fatal编程技术网

List 如何在CakePHP中创建线程列表?

List 如何在CakePHP中创建线程列表?,list,cakephp,multithreading,List,Cakephp,Multithreading,我创建表:id、name、thread\u id 主线程的线程id=0,但其子线程的线程id=id为父线程,如何创建包含子线程的列表是最好、最简单的解决方案,如下所示: 类别1 产品1 产品2 类别2 产品3 等等 也许你有更好的办法来解决这个问题 对不起,我的英语:)我想最简单的方法可能是使用Cake自己的TreeBehavior。更多信息请访问。我从未亲自使用过它,但听到过一些好的东西。它应该提供您需要的所有工具(和说明)。我想最简单的方法可能是使用Cake自己的树行为。更多信息请访问。我从

我创建表:id、name、thread\u id 主线程的线程id=0,但其子线程的线程id=id为父线程,如何创建包含子线程的列表是最好、最简单的解决方案,如下所示:

  • 类别1
    产品1
    产品2
  • 类别2
    产品3
    等等
  • 也许你有更好的办法来解决这个问题


    对不起,我的英语:)

    我想最简单的方法可能是使用Cake自己的
    TreeBehavior
    。更多信息请访问。我从未亲自使用过它,但听到过一些好的东西。它应该提供您需要的所有工具(和说明)。

    我想最简单的方法可能是使用Cake自己的
    树行为。更多信息请访问。我从未亲自使用过它,但听到过一些好的东西。它应该提供您需要的所有工具(和说明)。

    最简单有效的方法之一是使用kicaj-pl提出的树行为。
    但我建议你考虑一下。它还使用嵌套树数据库模型,但允许您创建具有不同根id和独立左右值的多棵树(因此更新一棵树不会更新任何其他树)。

    最简单有效的方法之一是使用kicaj-pl提出的树行为。
    但我建议你考虑一下。它还使用嵌套树数据库模型,但允许您创建具有不同根id和独立左右值的多棵树(因此一棵树的更新不会更新任何其他树)。

    啊!我发现这样一句话:当你使用find('threaded')时,你必须输入'parent_id'来创建类似树的结构。。。 一切正常


    谢谢回复,再见

    啊!我发现这样一句话:当你使用find('threaded')时,你必须输入'parent_id'来创建类似树的结构。。。 一切正常


    谢谢回复,再见

    试试MPPT逻辑。为此,在数据库表中需要3个字段,即parent_id、lft、rght。为了使用CakePHP实现它,CakePHP已经为它提供了函数,请参考:)

    尝试它的MPPT逻辑。为此,在数据库表中需要3个字段,即parent_id、lft、rght。为了使用CakePHP实现它,CakePHP已经为此提供了函数,请参考:)

    1。首先,您的模型必须在模型文件(Modelname.php-在我的例子中是Post.php)中使用“树”行为

    2.接下来需要检索线程结果并将其传递给视图(ModelnamesController.php——在我的例子中是PostsController.php)

    3.最后,您可以使用一个模板,为上述结果呈现无限线程列表

    <div id="posts_navi">
    
        <? function renderPosts($postsArray, $tmpModel){
            //set return for the first time
            if(!isset($return)){ $return = ""; }
    
            $return .= '<ul>';
            //create list
            foreach ($postsArray as $post){
    
                    $return .= '<li>';
                    if($post['Post']['content'] != null){
                        $return .= $tmpModel->link($post['Post']['title'], array('action' => 'view', $post['Post']['id']),array('escape'=>false));
                    }else{
                        $return .= $post['Post']['title'];
                    }
    
                    //if post has children, go deeper
                    if(!empty($post['children'])){
                        $return .= renderPosts($post['children'], $tmpModel);
                    }
    
                    $return .= '</li>';
            }
            $return .= '</ul>';
    
            return $return;
        } ?>
    
        <? $tmpModel = $this->Html; // we have to pass html helper inside, I am not sure it this is best way but it works
        echo renderPosts($posts, $tmpModel); //finally, we render the $result returned. ?>
    
    </div>
    

    1.首先,您的模型必须在模型文件中使用“树”行为(Modelname.php-在我的例子中是Post.php)

    2.接下来需要检索线程结果并将其传递给视图(ModelnamesController.php——在我的例子中是PostsController.php)

    3.最后,您可以使用一个模板,为上述结果呈现无限线程列表

    <div id="posts_navi">
    
        <? function renderPosts($postsArray, $tmpModel){
            //set return for the first time
            if(!isset($return)){ $return = ""; }
    
            $return .= '<ul>';
            //create list
            foreach ($postsArray as $post){
    
                    $return .= '<li>';
                    if($post['Post']['content'] != null){
                        $return .= $tmpModel->link($post['Post']['title'], array('action' => 'view', $post['Post']['id']),array('escape'=>false));
                    }else{
                        $return .= $post['Post']['title'];
                    }
    
                    //if post has children, go deeper
                    if(!empty($post['children'])){
                        $return .= renderPosts($post['children'], $tmpModel);
                    }
    
                    $return .= '</li>';
            }
            $return .= '</ul>';
    
            return $return;
        } ?>
    
        <? $tmpModel = $this->Html; // we have to pass html helper inside, I am not sure it this is best way but it works
        echo renderPosts($posts, $tmpModel); //finally, we render the $result returned. ?>
    
    </div>
    
    
    
    我知道这一点,我也使用过,但树行为适用于无限级别,但是,我想创建最简单的树,只有两个级别(父级和子级)。树在这一刻的行为,将是“太大”:)我知道在CakePHP中有find('threaded'),但我不能理解这一点…听起来你可能在追求这个:。我不知道细节,但它似乎使用了嵌套集和邻接列表模型的混合。我知道这一点,我也使用了,但树行为是无限级别的,但是,我想创建最简单的树,只有两个级别(父级和子级)。树在这一刻的行为,将是“太大”:)我知道在CakePHP中有find('threaded'),但我不能理解这一点…听起来你可能在追求这个:。我不知道细节,但它似乎使用了嵌套集和邻接列表模型的混合。
    <div id="posts_navi">
    
        <? function renderPosts($postsArray, $tmpModel){
            //set return for the first time
            if(!isset($return)){ $return = ""; }
    
            $return .= '<ul>';
            //create list
            foreach ($postsArray as $post){
    
                    $return .= '<li>';
                    if($post['Post']['content'] != null){
                        $return .= $tmpModel->link($post['Post']['title'], array('action' => 'view', $post['Post']['id']),array('escape'=>false));
                    }else{
                        $return .= $post['Post']['title'];
                    }
    
                    //if post has children, go deeper
                    if(!empty($post['children'])){
                        $return .= renderPosts($post['children'], $tmpModel);
                    }
    
                    $return .= '</li>';
            }
            $return .= '</ul>';
    
            return $return;
        } ?>
    
        <? $tmpModel = $this->Html; // we have to pass html helper inside, I am not sure it this is best way but it works
        echo renderPosts($posts, $tmpModel); //finally, we render the $result returned. ?>
    
    </div>