0

I am trying to use image CRUD in Codeigniter. The following is what I have working:

Controller:

public function view($page = 'home')
{
    $image_crud = new image_CRUD();

    $image_crud->unset_upload();
    $image_crud->unset_delete();

    $image_crud->set_primary_key_field('id');
    $image_crud->set_url_field('url');
    $image_crud->set_table('example_4')
    ->set_image_path('assets/uploads');

    $output = $image_crud->render();
    $this->load->view('pages/'.$page,$output);      
}

View:

<html>
<body><div class="container_main">

<?php echo $output; ?>

</div>

The page display properly with the about code. However, once i add an additional page the page will give me an error:

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: output

Filename: pages/gallery.php

Line Number: 7

new controller:

public function view($page = 'home')
{
    if($page == 'gallery'){
    $image_crud = new image_CRUD();

    $image_crud->unset_upload();
    $image_crud->unset_delete();

    $image_crud->set_primary_key_field('id');
    $image_crud->set_url_field('url');
    $image_crud->set_table('example_4')
    ->set_image_path('assets/uploads');

    $output = $image_crud->render();
    $this->load->view('pages/'.$page,$output);      

    }

}

What am I doing wrong?

Jenz
  • 8,280
  • 7
  • 44
  • 77
Ray
  • 13
  • 2

1 Answers1

0

try

on view :-

print_r($data);

Also need to change args in function

public function view($page) {
  $page = (!empty($page) ? $page :'home');
  if($page == 'gallery'){
    $image_crud = new image_CRUD();
    $image_crud->unset_upload();
    $image_crud->unset_delete();

    $image_crud->set_primary_key_field('id');
    $image_crud->set_url_field('url');
    $image_crud->set_table('example_4')
    ->set_image_path('assets/uploads');
    $data['output']= $image_crud->render();
    $data['page'] = $page;
    $this->load->view('pages/'.$page,$data); 
  }
  else {
    $data['page'] = $page;
    $this->load->view('pages/'.$page,$data);
  }

}
Rakesh Sharma
  • 13,680
  • 5
  • 37
  • 44
  • Thanks for the quick reply. The error message is gone, but is not the the result is not what I excepted. I was excepting to see the images, but now it is only showing the number '1'. – Ray May 17 '14 at 04:43
  • Also, if I am to change my controller back to: public function view($page = 'home') { $image_crud = new image_CRUD(); .... $this->load->view('pages/'.$page,$output); } it will show me the images and other data info like "stdClass Object ( [output] => images[js_files] => Array ( [4ee917aadfbe25ae7215325bcac7e24631d17826] => localhost/test/assets/image_crud/js/jquery-1.8.2.min.js ...." – Ray May 17 '14 at 04:55
  • so fetch your data like $output->output and son on – Rakesh Sharma May 17 '14 at 05:33
  • Sorry, I am confuse. If the controller does not contain the `if($page == 'gallery')` the I will get all the data in the $output variable including the images, CSS, and jsfile at the home page. I can fetch the data from that. but if i add the `if($page == 'gallery')` in the controller, i don't get any of those data, how can i fetch the data? In other word, if i go to http://localhost/test/ everything is display properly, but http://localhost/test/gallery i am missing all the data that i can see in http://localhost/test/. it seems like the data is not passing to http://localhost/test/gallery. – Ray May 17 '14 at 13:22