Welcome Guest, Not a member yet? Register   Sign In
Q: get_filename
#1

[eluser]Cosizzle[/eluser]
First off hello.

Ive been looking for a while now for a framework for my php; for a while it was Smarty. Then I came across this and am much more impressed.

In anycase I am going through the learning curve. Im wanting to display images within a folder so what ive done is:

1. within my constructor
Code:
$this->load->helper('file');

2. in a method
Code:
$data['imgDir'] = get_filenames('public/img/');

3. in a view
Code:
<?php
    foreach($imgDir as $imgs)
    {
        echo $imgs;
    }
?>

Im not sure if its my path or the way im trying to hold the array of data.

The Error being output is
Code:
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: body/img_view.php
Line Number: 4
#2

[eluser]Michael Wales[/eluser]
How are you loading the view? Make sure you are passing the second parameter which should be your $data array.
#3

[eluser]Cosizzle[/eluser]
Sorry, ya I am

Code:
$this->load->view('body/img_view',$data)
#4

[eluser]Michael Wales[/eluser]
Code:
if ($imgDir === FALSE) {
  echo 'get_filenames has an error';
}

Bet your path is incorrect - remember the path is relative from index.php.
#5

[eluser]Cosizzle[/eluser]
I got it, it was the paths. Relative from index... heh.
Code:
$data['imgDir'] = get_filenames('system/application/public/img/');
#6

[eluser]kalebheitzman[/eluser]
I find this solution works fine when I'm not passing it through the parser. When I do pass it through the parser I get the same foreach error.

Code:
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: libraries/Parser.php
Line Number: 131

Is there a solution to allow templating?




Theme © iAndrew 2016 - Forum software by © MyBB