简体   繁体   English

Codeigniter-在自定义页面上实现Ion_auth

[英]Codeigniter - Implementing Ion_auth on custom pages

I'm new to CI and Ion_auth is the first library I'm trying out. 我是CI的新手,Ion_auth是我正在尝试的第一个库。 Installing Ion_auth has been easy... no problem at all, I can navigate to /auth and all the example features are working fine. 安装Ion_auth很容易...完全没有问题,我可以导航到/ auth,所有示例功能都可以正常工作。

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. 您还必须复制控制器调用,因为在显示视图使其工作之前,您需要加载Ion_auth和auth_helper。

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. 并在Ion_Auth的演示控制器中查找可能需要加载才能使其工作的其他元素。 Also, set your default values in the form as empty, cause $message and other doesnt't exist. 另外,将表单中的默认值设置为空,导致$message以及其他不存在。

My tip is really to duplicate what the demo controller of Ion_auth is doing. 我的提示实际上是复制Ion_auth的演示控制器正在做的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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