CodeIgniter Forums
why's that no data showing on my sidebar,even if it's on my admin or user side? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: why's that no data showing on my sidebar,even if it's on my admin or user side? (/thread-72248.html)



why's that no data showing on my sidebar,even if it's on my admin or user side? - J.A - 11-26-2018

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');
}
}



RE: why's that no data showing on my sidebar,even if it's on my admin or user side? - Pertti - 11-27-2018

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.


RE: why's that no data showing on my sidebar,even if it's on my admin or user side? - soneax - 11-27-2018

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.


RE: why's that no data showing on my sidebar,even if it's on my admin or user side? - InsiteFX - 11-28-2018

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.


RE: why's that no data showing on my sidebar,even if it's on my admin or user side? - dave friend - 11-28-2018

(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');