0

我正在尝试使用 Ion Auth 来保护我网站上的管理区域。

我安装了 Ion Auth(添加表格、复制文件)。

我添加了文件 application/system/core/MY_Controller.php,如下所示:

<?php
class Admin_Controller extends CI_Controller {

    //Class-wide variable to store user object in.
    protected $the_user;

    public function __construct() {

        parent::__construct();

        if (!$this->ion_auth->is_admin() ) 
        {
            redirect('/auth/login');
        }
    }
}
?>

在管理区域的所有控制器中,我将 CI_Controller 更改为 Admin_Controller,如下所示:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Start extends Admin_Controller 
{
public function index()
{
        $this->load->view('layout/_header');
        $this->load->view('layout/_left');
        $this->load->view('admin/start');
        $this->load->view('layout/_footer');
}
}

现在我想弄清楚如何创建自己的登录表单,并用我的布局视图包装。

我不知道该怎么做。在 'auth/login' 控制器视图以某种奇怪的方式加载:

$this->_render_page('auth/login', $this->data);

有人可以帮我编写登录表单,这将与我加载视图的方法兼容吗?

我的意思是那个方法:

$this->load->view('layout/_header');
$this->load->view('layout/_left');
$this->load->view('admin/login'); // i want to load login form here
$this->load->view('layout/_footer');
4

2 回答 2

2

我建议阅读以下内容:http: //benedmunds.com/ion_auth/
登录视图:

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

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

  <p>
    <?php echo lang('login_identity_label', 'identity');?>
    <?php echo form_input($identity);?>
  </p>

  <p>
    <?php echo lang('login_password_label', 'password');?>
    <?php echo form_input($password);?>
  </p>

  <p>
    <?php echo lang('login_remember_label', 'remember');?>
    <?php echo form_checkbox('remember', '1', FALSE, 'id="remember"');?>
  </p>


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

<?php echo form_close();?>

<p><a href="forgot_password"><?php echo lang('login_forgot_password');?></a></p>
于 2013-11-20T09:35:05.810 回答
0

公共函数 __construct() { parent::__construct();

    // Check if the user is already logged in       
    if (!$this->ion_auth->logged_in()) {
        // If not, we send him to the login Page
        redirect('admin/user/login', 'refresh');
    }
}
于 2015-07-30T09:45:24.300 回答