CodeIgniter Forums
Total noob lookin' for some help... - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Total noob lookin' for some help... (/thread-13377.html)

Pages: 1 2


Total noob lookin' for some help... - El Forum - 11-20-2008

[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 {

    function Welcome()
    {
        parent::Controller();    
    }
    
    function index()
    {
    $this->load->library('listfiles', array('php','jpg', 'jpeg', 'csv'));
        $data['files'] = $this->listfiles->getFiles('./');
    
    
    $this->load->view('welcome_message',$data);
    }
}

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


Total noob lookin' for some help... - El Forum - 11-20-2008

[eluser]Nick Husher[/eluser]
What exactly is being displayed on the Welcome page?


Total noob lookin' for some help... - El Forum - 11-20-2008

[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


Total noob lookin' for some help... - El Forum - 11-20-2008

[eluser]davidbehler[/eluser]
to "echo" an array you have to use the function "print_r" instead.

Try this:
Code:
<?php print_r($files) ?>



Total noob lookin' for some help... - El Forum - 11-20-2008

[eluser]BobbyB[/eluser]
Hi waldmeister,
thanks for helping me out.
I will try that asap.

Cheers


Total noob lookin' for some help... - El Forum - 11-20-2008

[eluser]BobbyB[/eluser]
Hey, I just tried it out - and guess what...
It worked!
That made my day Smile

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 Smile



Cheers


Total noob lookin' for some help... - El Forum - 11-20-2008

[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)
{
    echo "<b>".$file['title']."</b> - ".$file['file']."</br>";
}

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.


Total noob lookin' for some help... - El Forum - 11-21-2008

[eluser]BobbyB[/eluser]
Hi waldmeister,
thanks for that info.
I did it with:

Code:
$count = count($files);
for($i=0; $i < $count; $i++) {
echo $files[$i]['file']."<br>";
}

But I will try out your solution too.
Cheers


Total noob lookin' for some help... - El Forum - 11-21-2008

[eluser]Nick Husher[/eluser]
The two methods are doing approximately the same thing. The foreach is arguably easier to read, though.


Total noob lookin' for some help... - El Forum - 11-22-2008

[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.