简体   繁体   中英

login form does not appear

I am new to CodeIgniter and I use Tank Auth for my login form. When I try to put Tank Auth in my template, the login form doesn't appear at all. I didn't change anything but the controller.

Here is my controller code:

public function __construct(){
    parent::__construct();
    $this->load->helper(array('form','url'));
    $this->load->library('tank_auth');
    //$this->load->model('users_model');
}
public function index(){
    if (!$this->tank_auth->is_logged_in()) {
        $data['loginform']='login_form';
        $this->load->view('tampilan',$data);
        //redirect('/auth/login/');
    } else {
        $data['user_id']    = $this->tank_auth->get_user_id();
        $data['username']   = $this->tank_auth->get_username();
        $this->load->view('welcome', $data);
    }               
}

and here is my template in the view folder:

<div id="page">

<div id="bg1">

    <div id="bg2">

        <div id="bg3">

            <!-- content -->

            <?php  $this->load->view($loginform); ?>

            <!-- end content -->

            <!-- sidebar -->

            <?php echo $this->load->view('content'); ?>

            <!-- end sidebar -->

        </div>

    </div>

</div>

It's simple code, I think, because I just change the controller, but why doesn't it appear in the browser?

The code, in itself, looks correct. What I can say is that might be that you're calling the wrong view, and have an error reporting level too low to show you errors. I mean:

  1. Is your login_form.php view a custom one? Is the path right? Try using a simple almost empty view (don't know, with just an "hello world" text in it?) to see if it gets called correctly.
  2. If you're using the default login_form.php view provided by Tank Auth, and you copied the content as is, the view should be inside the folder auth (so it comes in the downloaded package). Therefore you should call it with $data['auth/login_form']; in your controller,
  3. In the eventuality of point 2), the original Tank Auth login_form.php contains a lot of variables which happen to be undefined in your code. If you don't display errors, you get a blank page then. Set the ENVIRONMENT to "development" in index.php, and if that's not enough place this at the beginning of your index.php

     error_reporting(E_ALL); ini_set('display_errors',1); 

    To just test the functinality of Tank Auth, try calling it with the original controller by going to http://www.yoursite.com/index.php/auth . If that works, have a look at the login() method of the auth controller, you'll see how and which variable the original login_form.php needs.

  4. Minor point, you don't need to echo a view, so $this->load->view('content'); is enought.

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