【问题标题】:Recursive function in a CakePhHP Component not workingCakePhHP 组件中的递归函数不起作用
【发布时间】:2014-01-31 04:30:20
【问题描述】:

我正在尝试使用递归函数来列出目录中的所有文件夹/文件。 事实是这个函数没有回调,显示“Call to undefined function list_directory_contents()”。 我尝试了其他递归函数,结果相同。 虽然朋友似乎没有同样的问题。

这是我的函数:`function list_directory_contents($dir){

     $dh = new DirectoryIterator($dir);    
     foreach ($dh as $item) {
         if (!$item->isDot()) {
            if ($item->isDir()) {
                list_directory_contents("$dir/$item");
            } else {
                echo $dir . "/" . $item->getFilename();
                echo "<br>";
            }
         }
      }
}`

请注意,我使用的是 cakephp。

感谢您的帮助。

【问题讨论】:

    标签: function cakephp recursion components


    【解决方案1】:

    这与递归无关。在 cakePHP 组件中,您是在一个班级中。在方法调用之前添加 $this->。

    Calling functions in cakephp

    【讨论】:

      【解决方案2】:

      使用Folder::findRecursive()

      为什么要从组件中回显 html?这是完全错误的,违反了 MVC 模式。

      【讨论】:

      • 好吧,我也将它用作助手,结果相同,所以我尝试使用组件,但确实,这不是更好的选择。
      猜你喜欢
      • 2018-07-14
      • 2018-04-02
      • 2014-04-03
      • 1970-01-01
      • 2020-07-26
      • 2018-04-19
      • 2021-10-28
      • 1970-01-01
      相关资源
      最近更新 更多