0

我创建了一个管理员登录面板。这是我的模型、视图、控制器文件。如果登录不成功,那么我想发送一个querystring. 获取querystring值后我想设置一条消息

Incorrect email/password.

我认为我们必须修改某些catalog_model.php内容或其他内容?

我的控制器(D:\wamp\www\CodeIgniter\application\controllers\admin\catalog.php)

class Catalog extends CI_Controller
{

public function __construct()
{
    parent::__construct();
    $this->load->library('session');
    $this->load->model('catalog_model');
}

function index()
{   
    $this->load->helper(array('form', 'url'));
    $this->load->library('form_validation');
    $this->load->view('admin/templates/header');
    $this->form_validation->set_error_delimiters('<div class="error_admin">', '</div>');
    $this->load->database();
    $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
    $this->form_validation->set_rules('password', 'Password', 'required');
    if ($this->form_validation->run() == FALSE)
    {
        $this->load->view('admin/catalog/catalog_view');
    }
    else
    {   
        $this->catalog_model->admin_login();
    }
    $this->load->view('admin/templates/footer');
    //$html_string = $this->load->view('admin/catalog/catalog_view');
}

function logout()
{
    $this->session->unset_userdata('admin_login'); 
    $this->session->unset_userdata('admin_email');
    //print_r($this->session->all_userdata());
    $this->load->view('admin/catalog/catalog_view');
}

}

我的模型(D:\wamp\www\CodeIgniter\application\models\cataalog_model)

<?php
class Catalog_model extends CI_Model {

    public function __construct()
    {
        $this->load->database();
    }

    public function admin_login()
   {
        $data = array(
        'email' => $this->input->post('email'),
        'password' => $this->input->post('password'),
        );
        //return $this->db->insert('school_registration', $data);
        $query = $this->db->get_where('admin', $data);
        $rowcount = $query->num_rows();
        if($rowcount==1)
        {
        $this->session->set_userdata('admin_login', 'true');
        $this->session->set_userdata('admin_email', $this->input->post('email'));
        $this->load->view('admin/catalog/home_view');
        }
        else
        {
            $this->load->view('admin/catalog/catalog_view');
            //parse_str($_SERVER['QUERY_STRING'],$_GET);
        }
   }
}

我的观点(D:\wamp\www\CodeIgniter\application\views\admin\catalog\catalog_view.php)

<?php if (!defined('BASEPATH')) exit(__('No direct script access allowed')); ?>
<div class="light_blue_back" align="center">
     <div class="adminbox">
     <?php echo form_open('admin/catalog'); ?>
          <fieldset>
            <legend><b>Admin Login</b></legend>
            <dl>
                <dt>
                    <label for="street_address1"> <span class="req">*</span>Email</label>
                </dt>
                <dd>
                    <input type="text"  name="email" id="email"  value="<?php echo set_value('email'); ?>"/><?php echo form_error('email'); ?>
                </dd>
            </dl>
            <dl>
                <dt>
                    <label for="street_address2">Password</label>
                </dt>
                <dd>
                    <input type="password" name="password" id="password"  value="<?php echo set_value('password'); ?>"/><?php echo form_error('password'); ?>
                </dd>
            </dl>
            <dl>
                <dt>
                </dt>
              <dd>
                  <?php echo form_submit('reg_sub', 'Submit');?>
                  <?php echo form_reset('reg_reset', 'Reset');?>
              </dd>
            </dl>
        </fieldset>
    <?php //echo form_close('admin/catalog'); ?>
    </form>
     </div>
</div>
4

1 回答 1

0

您可以使用set_flashdata此会话函数显示错误消息,示例代码为:

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

$this->session->set_flashdata('loginerror', 'Username and password mismatch');

您可以在查看页面上loginerror flashdata使用PHP 函数显示这一点。isset

有关更多详细信息,请访问此链接:

http://ellislab.com/codeigniter/user-guide/libraries/sessions.html

于 2013-07-16T12:46:48.573 回答