Undefined variable: admin_id |
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
As, the error message says, line 16 in C:\xampp\htdocs\dgos\application\views\admins\admin-profile.php has not been set.
(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>
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
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.
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. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
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. |
Welcome Guest, Not a member yet? Register Sign In |