Welcome Guest, Not a member yet? Register   Sign In
Undefined variable: admin_id
#9

Make sure you have an array key named 'admin_id' in your controller, and pass the array to the view.

Controller:
PHP Code:
$data['admin_id'] = 123;
$data['other_stuff'] = 'Other stuff';
$this->load->view('admins\admin-profile'$data); 
This way, the $admin_id variable is also available in your view.

Even better: get the $profile_info records in your controller instead of the view.
Controller:
PHP Code:
$data['profile_info'] = $this->db->get_where('admin' , array('admin_id' => $admin_id))->result_array();
$this->load->view('admins\admin-profile'$data); 
Now, in your view, $profile_info is an array that you can loop through.

And even better than that: create a model to retrieve the records from your database and use CI's query builder.
Model (Admin_model.php):
PHP Code:
public function get_admin_profile($admin_id)
{
 
  $query $this->db->where('admin_id'$admin_id)->get('admin');
 
  if ($query->num_rows() == 0) {
 
    return FALSE;
 
  else {
 
    return query->result_array();
 
  }


Controller:
PHP Code:
$this->load->model('admin_model');
$data['profile_info'] = $this->admin_model->get_admin_profile(123);
$this->load->view('admins\admin-profile'$data); 

This will keep your controllers lean. Load the model in any controller where you need the admin profile.
Reply


Messages In This Thread
Undefined variable: admin_id - by Saeed_Sikandar - 01-10-2019, 11:26 PM
RE: Undefined variable: admin_id - by ciadmin - 01-10-2019, 11:28 PM
RE: Undefined variable: admin_id - by ciadmin - 01-11-2019, 12:48 AM
RE: Undefined variable: admin_id - by InsiteFX - 01-11-2019, 04:50 AM
RE: Undefined variable: admin_id - by Codehoster - 08-24-2019, 12:10 AM
RE: Undefined variable: admin_id - by Wouter60 - 08-24-2019, 07:52 AM
RE: Undefined variable: admin_id - by InsiteFX - 08-24-2019, 04:06 PM



Theme © iAndrew 2016 - Forum software by © MyBB