Total noob lookin' for some help... |
[eluser]BobbyB[/eluser]
Hi, I am all new to this framework(to php/frameworks all together) and looked at some beginner tutorials like the one at capsizedesigns but am having a hard time wrapping my head around it. Even the installation was kind of tricky. But then I was finally ready to go and played around with some code I found in the Wiki: http://codeigniter.com/wiki/Listfiles/ What I am trying to do is list the files of a directory on the welcome page. I changed the welcome.php to: Code: class Welcome extends Controller { And in the welcome_message.php I tried following: Code: <?php echo $files ?> I also added the code to -> application/libraries/Listfiles.php. But of course it wont work. Could someone please give me a hint/some code how to solve this? Thanks in advance. Cheers
[eluser]Nick Husher[/eluser]
What exactly is being displayed on the Welcome page?
[eluser]BobbyB[/eluser]
Hi Nick, thanks for your help. The welcome page shows -> "array". I played around with "foreach" and stuff like that but had no luck so far. I guess its not working because I try to display the array in a wrong way? Cheers
[eluser]davidbehler[/eluser]
to "echo" an array you have to use the function "print_r" instead. Try this: Code: <?php print_r($files) ?>
[eluser]BobbyB[/eluser]
Hi waldmeister, thanks for helping me out. I will try that asap. Cheers
[eluser]BobbyB[/eluser]
Hey, I just tried it out - and guess what... It worked! That made my day This forum seems to be full of professional&helpful;people. Even if you are not a pro, and get on their nerves with stupid questions. Thanks again. Now I have to find a way to style the array in a nice way. Will this ever end? - I hope not Cheers
[eluser]davidbehler[/eluser]
Instead of using "print_r" you could do the following: Go through your $files array using a foreach loop. That way you can output each entry in your array the way you want to. Code: foreach($files as $file) This code is untested and I am not sure about the indices but that should give you and impression on how you can output your array the way to want to.
[eluser]BobbyB[/eluser]
Hi waldmeister, thanks for that info. I did it with: Code: $count = count($files); But I will try out your solution too. Cheers
[eluser]Nick Husher[/eluser]
The two methods are doing approximately the same thing. The foreach is arguably easier to read, though.
[eluser]thomasz[/eluser]
My standard code for debugging and testing array values is this: echo "<pre>"; print_r($array_name); echo "</pre>"; exit; The html '<pre>' tags preserve the line breaks so the print_r output is formatted and readable. I put this block of code as a ctl+key shortcut in my editor so i can use it quickly. It saves lots of time. |
Welcome Guest, Not a member yet? Register Sign In |