![]() |
Undefined variable: admin_id - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Undefined variable: admin_id (/showthread.php?tid=72602) |
Undefined variable: admin_id - Saeed_Sikandar - 01-10-2019 New to Codeigniter need help
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: admin_id
Filename: admins/admin-profile.php
Line Number: 16
Backtrace:
File: C:\xampp\htdocs\dgos\application\views\admins\admin-profile.php
Line: 16
Function: _error_handler
File: C:\xampp\htdocs\dgos\application\controllers\Admins.php
Line: 47
Function: view
File: C:\xampp\htdocs\dgos\index.php
Line: 315
Function: require_once
RE: Undefined variable: admin_id - ciadmin - 01-10-2019 As, the error message says, line 16 in C:\xampp\htdocs\dgos\application\views\admins\admin-profile.php has not been set. RE: Undefined variable: admin_id - Saeed_Sikandar - 01-10-2019 (01-10-2019, 11:28 PM)ciadmin Wrote: As, the error message says, line 16 in C:\xampp\htdocs\dgos\application\views\admins\admin-profile.php has not been set.here is the view page I define it please take a look <div class="card-body"> <?php $profile_info = $this->db->get_where('admin' , array('admin_id' => $admin_id))->result_array(); foreach($profile_info as $row):?> <div class="mx-auto d-block"> <img class="rounded-circle mx-auto d-block" src="<?php echo base_url().'assets/' ; ?>images/icon/avatar-11.jpeg" alt="Card image cap"> <h5 class="text-sm-center mt-2 mb-1"><?php echo $row['name'];?></h5> <div class="location text-sm-center"> <i class="fa fa-map-marker"></i> Karachi, Pakistan</div> </div> RE: Undefined variable: admin_id - Saeed_Sikandar - 01-10-2019 Yes sir but I define this variable in admin-profile. Should I define that variable again in a controller of this view page or not RE: Undefined variable: admin_id - ciadmin - 01-11-2019 I don't see $admin_id defined there. I see an array, where the key 'admin_id' references some variable $admin_id, which must be defined elsewhere or you will get an undefined variable error message. Hmmmmm. RE: Undefined variable: admin_id - InsiteFX - 01-11-2019 For one you should not be running database queries in the view that should be done in the controller. Then assign the result to the $data array pass it to the view then loop through it. RE: Undefined variable: admin_id - Saeed_Sikandar - 01-12-2019 (01-11-2019, 12:48 AM)ciadmin Wrote: I don't see $admin_id defined there. I see an array, where the key 'admin_id' references some variable $admin_id, which must be defined elsewhere or you will get an undefined variable error message. Hmmmmm. Alright thanks RE: Undefined variable: admin_id - Codehoster - 08-24-2019 Try to add if (!empty($admin_id)) { // your code } RE: Undefined variable: admin_id - Wouter60 - 08-24-2019 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; 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(); 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) Controller: PHP Code: $this->load->model('admin_model'); This will keep your controllers lean. Load the model in any controller where you need the admin profile. RE: Undefined variable: admin_id - InsiteFX - 08-24-2019 @Wouter60, These are old posts the new users just reply to them to get recognized. |