codeigniter - A PHP Error was encountered Severity: Notice Message: Undefined variable: data Filename: profile/viewabout.php Line Number: 79 -


controller: i'm trying fetch records database, showing undefined variable $data in view section. problem don't understand.

public function vabout(){     if(!$this->session->userdata('logged_in')){         redirect('register/login');     }     $this->load->model('profile_model');     $data = $this->profile_model->viewprofile();      $this->load->view('templates/pheader');     $this->load->view('profile/viewabout',$data);     $this->load->view('templates/pfooter');  } 

model: model section, there issue in model fetching record?

public function viewprofile(){     $data = $this->db->get('profile');     return $data->row_array(); } 

view: errore: php error encountered $data undefined

<?php       foreach ($data $row)         { ?>         <p><?php echo $row->id; ?></p>         <p><?php echo $row->name; ?></p>         <?php       }   ?> 

you need pass array key name $datanot contain data key name, every key pass data array become variable in view

public function vabout(){                 if(!$this->session->userdata('logged_in')){                     redirect('register/login');                 }                 $this->load->model('profile_model');                 $data['data'] = $this->profile_model->viewprofile(); // add data index                  $this->load->view('templates/pheader');                 $this->load->view('profile/viewabout',$data);                 $this->load->view('templates/pfooter');              } 

also retrieving data in view object. in model not convert result in array

public function viewprofile(){     $data = $this->db->get('profile');     return $data->result(); } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -