Welcome Guest, Not a member yet? Register   Sign In
Variables are not passing in view from my controller
#5

Try changing your do_upload like this:

PHP Code:
   public function do_upload()
 
   {
 
       $config['upload_path'] = './assets/images/uploads/promo/';
 
       $config['allowed_types'] = 'jpg|png';
 
       $config['max_size'   '2000';
 
       $config['max_width' '3000';
 
       $config['max_height' '1768';

 
       $this->load->library('upload'$config);

 
       $data = array(
 
           'error' => '',
 
           'upload_data' => '',
 
       );

 
       if (! $this->upload->do_upload()) {
 
           $data['error'] = $this->upload->display_errors();
 
       } else {
 
           $data['upload_data'] = $this->upload->data();
 
       }

 
       $this->load->view('admin/upload_promo'$data);
 
   

Then, in your view:

PHP Code:
if (empty($upload_data)) {
 
   echo empty($error) ? "An unknown error occurred when attempting the upload." $error;
 else {
 
   echo "Image Uploaded Sucessfuly!";


Most of the changes are just cleanup, but, in general, I would avoid using the same variable name ($data) to reference multiple things, and I would avoid nesting arrays where it isn't necessary. Additionally, empty() or isset() help to avoid undefined variable errors when checking viewdata (though you have to be careful with empty(), especially if you pass boolean values to a view). The same warning applies to using $variable != "" instead of $variable !== "".
Reply


Messages In This Thread
RE: Variables are not passing in view from my controller - by mwhitney - 03-12-2015, 10:17 AM



Theme © iAndrew 2016 - Forum software by © MyBB