简体   繁体   中英

Codeigniter - Implementing Ion_auth on custom pages

I'm new to CI and Ion_auth is the first library I'm trying out. Installing Ion_auth has been easy... no problem at all, I can navigate to /auth and all the example features are working fine.

So now I want to implement a login form on my custom page (I don't want to use the example view structure), I copied the following code into my own view:

<p>Please login with your email address and password below.</p>

<div id="infoMessage"><?php echo $message;?></div>

<?php echo form_open("auth/login");?>

  <p>
    <label for="email">Email:</label>
    <?php echo form_input($email);?>
  </p>

  <p>
    <label for="password">Password:</label>
    <?php echo form_input($password);?>
  </p>

  <p>
      <label for="remember">Remember Me:</label>
      <?php echo form_checkbox('remember', '1', FALSE);?>
  </p>


  <p><?php echo form_submit('submit', 'Login');?></p>


<?php echo form_close();?>

But that gives me the following errors:

Message: Undefined variable: message

Message: Undefined variable: identity

Message: Undefined variable: password

I understand my view isn't loading these variables, but how are they being loaded in the example view?

I'm just looking for an explanation on how the library works and what do I need to do in order to get it working outside of the examples.

You have to duplicate the controller calls too, because you need to load Ion_auth and the auth_helper before showing the view to make it work.

Add this in your controller, just before outputting the view:

$this->load->library('ion_auth');

And look in the demo controller of Ion_Auth for other element you might need to load to make it work. Also, set your default values in the form as empty, cause $message and other doesnt't exist.

My tip is really to duplicate what the demo controller of Ion_auth is doing.

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