Welcome Guest, Not a member yet? Register   Sign In
I have a probelm with view
#1

[eluser]ivelin[/eluser]
In my controller
Code:
function get_images(){
        $file= scandir($this->gallery_path);
      
        $file= array_diff($file, array('.', '..', 'thumbs'));
      //   print_r($file);
        $image= array();

        foreach ($file as $key=> $f){
        
            $image[$key]['info']= array(
                'url'=>  $this->gallery_path_url.$f,
                'thum_url' =>  $this->gallery_path_url.'thumbs/'.$f
            );
          
        }
      $this->load->view('upload_success', $image);
    }

and my view
Code:
<div id="images">
      
            &lt;?
                foreach ($image as $row){ ?&gt;
            <div id="thumb">
                <a href="&lt;?php echo $row['url'];?&gt;"><img src="&lt;?php echo $row['thum_url']; ?&gt;" /> </a>
            </div>
&lt;?php } ?&gt;
          
        
        </div>


Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: image

Filename: views/upload_success.php
Where is my mistake??
#2

[eluser]cpass78[/eluser]
Does the following work?

Code:
function get_images() {
        $file = scandir ( $this->gallery_path );
        
        $file = array_diff ( $file, array ('.', '..', 'thumbs' ) );
        //   print_r($file);
        $image = array ();
        
        foreach ( $file as $key => $f ) {
            $image ['url'] = $this->gallery_path_url . $f;
            $image ['thum_url'] = $this->gallery_path_url . 'thumbs/' . $f;
        }
        $this->load->view ( 'upload_success', $image );
    }
#3

[eluser]bubbafoley[/eluser]
you need to wrap $image in an array

Code:
$this->load->view('upload_success', array('image' => $image));
#4

[eluser]John_Betong_002[/eluser]
Hi ivelin

With your original source your loop overwrites $image[$key] ['info'] and you will only have the last item in your array.

Try this:
// controller
Code:
$path = 'path-to-your-picture-files';
$file = scandir(FCPATH .$path); // FCPATH set in index.php
$file = array_diff($file, array('.', '..', 'thumbs'));

$image= array();
foreach ($file as $key=> $f):
  $image['THUMBNAIL'][] = array
  (
    'url' => $path .$f,
    'thumb_url' => $path .$f
  );
endforeach;
$this->load->view ( 'upload_success', $image);


// view
Code:
echo "<dl  style='margin:2em'>";
  foreach($THUMBNAIL as $url => $pix):
    
    echo "<dt>" .$pix['url']        ."</dt>";
    echo "<dt>" .$pix['thumb_url']  ."</dt>";
      
    echo '<dd>'
          . anchor
            (
              base_url() .$pix['url'],
              "<img src='" .base_url() .$pix[' />"
            )
          .'<br /><br /></dd>';
  endforeach;
echo '</dl>';
&nbsp;
&nbsp;
edit: forgot the closing code tag Sad
#5

[eluser]ivelin[/eluser]
thanks!!
#6

[eluser]John_Betong_002[/eluser]
[quote author="ivelin" date="1311810095"]
thanks!!
[/quote]
&nbsp;
I am glad I was able to help.

Please prefix the thread title with [SOLVED]

&nbsp;
&nbsp;
#7

[eluser]toopay[/eluser]
Next time, it would be nice if someone post this kind thread on other section.
#8

[eluser]Unknown[/eluser]
Can't someone else mark it SOLVED ?




Theme © iAndrew 2016 - Forum software by © MyBB