Welcome Guest, Not a member yet? Register   Sign In
Total noob lookin' for some help...

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:

What I am trying to do is list the files of a directory on the welcome page.

I changed the welcome.php to:

class Welcome extends Controller {

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

And in the welcome_message.php I tried following:

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

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

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?


to "echo" an array you have to use the function "print_r" instead.

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

Hi waldmeister,
thanks for helping me out.
I will try that asap.


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


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

Hi waldmeister,
thanks for that info.
I did it with:

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

But I will try out your solution too.

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

My standard code for debugging and testing array values is this:

echo "<pre>";
echo "</pre>";

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.

Theme © iAndrew 2016 - Forum software by © MyBB