简体   繁体   中英

How to move to Dashboard welcome screen through logged-in dashboard breadcrumb, using session in Codeigniter?

I have created a login with specific array value in CodeIgniter, the dashboard loads after providing the correct credentials, along with login; Breadcrumb is displayed with the title 'HOME/Dashboard'.How to view the main dashboard page when the breadcrumb Home is clicked. If I'm creating seperate route for the home, the dasboard homepage is getting loaded even if logged-out.

Here is the code for Controller

public function adminLogin()
{
    $username = $this->input->post('username');
    $adminRecognition = $this->input->post('adminRecognition');
    $password = $this->input->post('password');

    if($username=='some_user' && $adminRecognition == '01234' && $password == 'some_pass')
    {
        $this->session->set_userdata(array('username'=>$username));
        $this->load->view('DashboardView/super_admin/superAdmin_View');
    }

    else
    {
        $data['error'] = 'Please enter a valid Credentials';
        $this->load->view('admin_login_portal/admin_portal',$data);
    }


}

public function adminLogout()
{
    $this->session->unset_userdata('username');
    
    $this->load->view('admin_login_portal/admin_portal');
}

Here is the code in the breadcrumb that loads at the other page

<div class="content-wrapper">
<!-- Content Header (Page header) -->
<div class="content-header">
  <div class="container-fluid">
    <div class="row mb-2">
      <div class="col-sm-6">
        <h1 class="m-0">Dashboard</h1>
      </div><!-- /.col -->
      <div class="col-sm-6">
        <ol class="breadcrumb float-sm-right">
          <li class="breadcrumb-item"><a href="#">Home</a></li>
          <li class="breadcrumb-item active">Dashboard</li>
        </ol>
      </div><!-- /.col -->
    </div><!-- /.row -->
  </div><!-- /.container-fluid -->
</div>

How to redirect with admin login page if session is not active, and how the home page would load on clicking the HOME link in the breadcrumb?

A redirection link can be created on href(s) of the other page with the name of a Controller performing a similar action. Here is the example of the code:

  <div class="content-wrapper">
<!-- Content Header (Page header) -->
<div class="content-header">
  <div class="container-fluid">
    <div class="row mb-2">
      <div class="col-sm-6">
        <h1 class="m-0">Dashboard</h1>
      </div><!-- /.col -->
      <div class="col-sm-6">
        <ol class="breadcrumb float-sm-right">
          <li class="breadcrumb-item"><a href="<?php echo base_url(); ?>name_of_the_Controller/method_redirecting_to_dashboard_home_view">Home</a></li>
          <li class="breadcrumb-item active">Dashboard</li>
        </ol>
      </div><!-- /.col -->
    </div><!-- /.row -->
  </div><!-- /.container-fluid -->
</div>

To check that the link is not misused with direct redirection, you can write the following Controller

public function superAdminDashboardView()
{
    if(!$this->session->userdata('username'))
    {
        $this->load->view('admin_login_portal/admin_portal');
    }
    else
    {
        $this->load->view('DashboardView/super_admin/superAdmin_View');
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM