This has nothing to do with recursion. In cakePHP components, you're in a class. Add $this-> before your method call.
Recursive function in a CakePhHP Component not working
-
04-10-2022 - |
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.
Solution
OTHER TIPS
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