在基于Ion Auth库的CodeIgniter中创建登录表单 [英] Creating a login form in CodeIgniter based on Ion Auth library

查看:247
本文介绍了在基于Ion Auth库的CodeIgniter中创建登录表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍然在CodeIgniter学习我的方式。

I'm still learning my way around in CodeIgniter.

我想在我的codeigniter应用程序中创建一个登录表单,基于 Ion Auth library

I'd like to create a login form in my codeigniter application based on Ion Auth library.

我已按照说明安装了库,并且在导航到auth / login,auth / create_user,auth / logout等时工作正常...

I have installed the library following the instruction and it works fine when navigating to auth/login, auth/create_user, auth/logout, etc...

但是,我不需要一个独立的登录页面,我想将表单嵌入我的主页。当我在我的首页使用示例提供的登录视图时,会出现以下错误:

However, I don't need a stand alone page for login, I'd like to embed the form in my homepage. When I use the sample provided login view in my homepage, I get the following errors:


  • 消息:未定义的变量:message

  • 消息:未定义的变量:identity

  • 消息:未定义的变量:password

我意识到上面的变量没有在我的视图中定义,我只是不知道在哪里和如何他们应该定义,为什么他们在提供的示例中提供的库工作很好?

I realize that the above variables are not defined in my view, I just can't figure out where and how they should be defined and why is that they work fine in the provided sample that came with the library?

推荐答案

config / routes.php

$route['login/check'] = 'auth/my_front_end_login';

查看

<?php echo form_open('login/check'); ?>

<fieldset>
    <legend>login Credentials<legend>

    <label for="identity">&lowast; Identity</label>
    <input type="text" name="identity" id="identity" value="<?php echo set_value('identity');?>" />
    <?php echo form_error('identity');?>

    <label for="password">&lowast; Password</label>
    <input type="password" name="password" id="password" value="<?php echo set_value('password');?>" />
    <?php echo form_error('password');?>

    <label for="message">&lowast; Message</label>
    <input type="text" name="message" id="message" value="<?php echo set_value('message');?>" />
    <?php echo form_error('message');?>
</fieldset>

<?php echo form_close();?>

controllers / auth

public function my_front_end_login(){
   if($this->form_validation->run('login_frontend')) // uses config/form_validation.php
   {
       //validation passed, now attempt login via ION_AUTH
       //open ION_Auth library file and see what the login method requests in its params. 
      if(ION_Auth::login($params)) // Im not familiar with it
      {
         //login success
      }
      else
      {
         //login failure
      }
   }
   else
   {
       $this->index();
   }
}

这篇关于在基于Ion Auth库的CodeIgniter中创建登录表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆