Question

I'm trying to use a recursive function wich list all folders/files in a directory. The fact is this function doesn't callback, displaying "Call to undefined function list_directory_contents()". I tried others recursive functions, same result. Althought a friend doesn't seems to have the same problem.

Here is my function : `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>";
            }
         }
      }
}`

Note that I'm using cakephp.

Thanks for helping.

Was it helpful?

Solution

This has nothing to do with recursion. In cakePHP components, you're in a class. Add $this-> before your method call.

Calling functions in cakephp

OTHER TIPS

Use Folder::findRecursive().

Why are you echoing html from a component? That's plain wrong and violates the MVC pattern.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top