简体   繁体   English

CodeIgniter中的Login_validation()无法正常工作?

[英]Login_validation() in CodeIgniter not working?

My code: 我的代码:

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

class Main extends CI_Controller {

public function index()
{
    $this->login();
}

public function login()
{
    $this->load->view('login');
}

public function members() 
{
    $this->load->view('members');
}

public function login_validation()

{
    $this->load->library('Form_validation');

    $this->form_validation->set_rules('email', 'Email', 'required');
    $this->form_validation->set_rules('password', 'Password', 'required');

    if ($this->form_validation->run() == TRUE)
    {
        redirect('main/members');
    }
    else 
    { 
        echo 'not working';
    }
}

} }

This is the login_validation function and this is the login form in the view: 这是login_validation函数,这是视图中的登录表单:

<?php 

    echo form_open('main/login_validation');

    echo validation_errors();

    echo "<p>Email: ";
    echo form_input('email');
    echo "</p>";

    echo "<p>Password: ";
    echo form_password('password');
    echo "</p>";

    echo "<p>";
    echo form_submit('login_submit','Login');
    echo "</p>";

    echo form_close();

?>

When I enter the email and password into the fields it returns "not working". 当我在字段中输入电子邮件和密码时,它将返回“不起作用”。

Also if I don't enter the email or password it also returns not working which means the library is unable to load I guess. 另外,如果我没有输入电子邮件或密码,它也会返回无法使用的状态,这意味着我无法加载该库。 I already double checked the documentation and everything seems to be right. 我已经仔细检查了文档,一切似乎都正确。 Any ideas? 有任何想法吗?

Before saying any thing i want to know , does any thing print or redirect to your desire uri? 在说出我想知道的任何事情之前,有什么事情可以打印或重定向到您想要的uri吗? If Not 1. At first have to know the version of CI. 如果不是1.首先必须知道CI的版本。 If you are using CI 3.00 then you should check you Controller file name and class name (Both should need start with UPPERCASE). 如果使用的是CI 3.00,则应检查控制器文件名和类名(两者都必须以大写字母开头)。 2.Check your .htaccess. 2.检查您的.htaccess。

Try by replacing your function with given below : 尝试用下面给出的替换函数:

 public function login_validation()
    {
        $this->load->library('form_validation');

        $this->form_validation->set_rules('email', 'Email', 'required');
        $this->form_validation->set_rules('password', 'Password', 'required');

        if ($this->form_validation->run() == FALSE)
        {
            echo 'not working';
        }
        else 
        { 
            redirect('main/members');
        }
    }

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

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