0
votes

i want to put login form in navigation(template) so that it will be shown in all the pages. and will check username and password in database without going to other pages. if failed, an error will be shown in the nav and if success, the page will be reloaded again with specific costomizations. please tell me how with code and details.

i have these parts in my template:

  1. header
  2. nav
  3. footer
  4. and content that will be added in current controller

i wanna do this in each controller:

$this->load->view('templates/header');
$this->load->view('templates/nav');
$this->load->view('related_view');
$this->load->view('templates/footer');

but my navigation should contain a login form which will not go to another page by submitting.

3

3 Answers

0
votes

I usually do something like this:

<?php
$this->load->view('templates/header');

if ($this->user_model->isLoggedIn())
{
    // Logged-in users should see this view
    $this->load->view('templates/nav-registered');
}
else
{
    // Guests should see this
    $this->load->view('templates/nav-guest');
}

$this->load->view('related_view');
$this->load->view('templates/footer');

You'll thank yourself if you override the Loader class to grab your header/footer for you automatically, not having to code this in EVERY controller method. Just a thought..

0
votes

use session to check loged user, and put this on the nav view, but first make sure you have session loaded from auload or from your controller

if($this->session->userdata('user_loged')){
      //code to put some navigation when use is loged
}else{
    //code to put login form
}
0
votes

The solution I found is to extend the Controller class. So In this case we should make an extended controller (for example MY_Controller) and put the dynamic action (here authentication) in it as a method.

Then we should extend this self-made controller in each of our controllers , so authentication in the template would be simply handled.