CodeIgniter Forums

Full Version: why's that no data showing on my sidebar,even if it's on my admin or user side?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
this is the picture of my sidebar:
[Image: qyY3Rfr]
this is my code in my sidebar:
Code:
<aside class="main-sidebar">
   <!-- sidebar: style can be found in sidebar.less -->
   <section class="sidebar">
     <!-- Sidebar user panel -->
     <br><br>
     <!-- sidebar menu: : style can be found in sidebar.less -->
     <ul class="sidebar-menu" data-widget="tree">
       <?php
        if($this->session->type == "admin"){ ?>
          <li>
           <a href="<?php echo base_url(); ?>userdata">
             <i class="fa fa-users"></i><span>User Data</span>
           </a>
         </li>
         <li>
           <a href="<?php echo base_url(); ?>category">
             <i class="fa fa-list-alt"></i><span>Category</span>
           </a>
         </li>
         <li>
           <a href="<?php echo base_url(); ?>brand">
             <i class="fa fa-book"></i><span>Brands</span>
           </a>
         </li>
         <li>
           <a href="<?php echo base_url(); ?>product">
             <i class="fa fa-product-hunt"></i><span>Products</span>
           </a>
         </li>
         <li>
           <a href="#">
             <i class="fa fa-first-order"></i><span>Orders</span>
           </a>
         </li>
       <?php
       } elseif($this->session->type == "user"){ ?>
         <li>
           <a href="#">
             <i class="fa fa-first-order"></i><span>Orders</span>
           </a>
         </li>
       <?php
       }
       ?>
     </ul>
   </section>
   <!-- /.sidebar -->
 </aside>


then this is my code in my login:
Code:
$this->form_validation->set_rules('username', 'Username', 'trim|required');

$this->form_validation->set_rules('password', 'Password', 'trim|required');
if($this->form_validation->run() == TRUE){
$username = $this->input->post('username');
$password = $this->input->post('password');
$email = $this->input->post('email');
$user_id = $this->login_model->login($username, $password);
if($user_id){
$session = array(
'user_id' => $user_id,
'username' => $username,
'email' => $email,
'logged_in' => true
);
$this->session->set_userdata($session);
foreach ($user_id as $users){
if($users->type == admin){
redirect(base_url() . 'category');
} elseif($users->type == user){
redirect(base_url() . 'profile');
}
}
Check your $this->session->type value - it looks like it has no fallback (which might be by design), so if it's not either 'admin' or 'user', it will never show anything.
Maybe i'm wrong but perhaps you're not saving the type in the user session and then you're looking for something that don't exist - nothing to show.
You can make your base_url look better by doing this:

PHP Code:
<a href="<?php echo base_url('product');?>"

And for your redirects like so:

PHP Code:
redirect(base_url('profile')); 

If your missing css file it will stop your sidebar from showing.

Because it has happened to me before.
(11-28-2018, 02:09 PM)InsiteFX Wrote: [ -> ]And for your redirects like so:

PHP Code:
redirect(base_url('profile')); 

The base_url( ...) part of the above is unnecessary. redirect() will figure out the "base" for you. It should look like this.

PHP Code:
redirect('profile');