1

我在处理 codeignitor 表单时遇到问题,它不会在本地服务器上执行$this->form_validation->run() 。但它在实时服务器上确实工作得很好。我不知道是什么原因。这是我的控制器。

class Login extends CI_Controller
{
    function __construct(){
    parent::__construct();

}   

  function removeUser($record_id){
$a = new Alumni();
$a->removeConnections($record_id);
  }

function index(){
    $redir = isset($_GET['redir'])?$_GET['redir']:'admin';
    if ($this->tank_auth->is_logged_in()) {                                 // logged in
        redirect('admin');
    } elseif ($this->tank_auth->is_logged_in(FALSE)) {                      // logged in, not activated
        redirect('/login/send_again/');
    } else {
                    //
        $data['login_by_username'] = ($this->config->item('login_by_username', 'tank_auth') AND
        $this->config->item('use_username', 'tank_auth'));
        $data['login_by_email'] = $this->config->item('login_by_email', 'tank_auth');

        $this->form_validation->set_rules('login', 'Login', 'trim|required|xss_clean');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
        $this->form_validation->set_rules('remember', 'Remember me', 'integer');
        // Get login for counting attempts to login
        if ($this->config->item('login_count_attempts', 'tank_auth') AND
                ($login = $this->input->post('login'))) {
            $login = $this->security->xss_clean($login);
                            //var_dump($login);
        } else {
            $login = '';
        }
                   //var_dump($this->input->post("remember"));
        $data['use_recaptcha'] = $this->config->item('use_recaptcha', 'tank_auth');
        if ($this->tank_auth->is_max_login_attempts_exceeded($login)) {
            if ($data['use_recaptcha'])
                $this->form_validation->set_rules('recaptcha_response_field', 'Confirmation Code', 'trim|xss_clean|required|callback__check_recaptcha');
            else
                $this->form_validation->set_rules('captcha', 'Confirmation Code', 'trim|xss_clean|required|callback__check_captcha');
        }

        $data['errors'] = array();
        $loginID = $this->input->post("login");
                    $pass = $this->input->post("password");
                    $remember = $this->input->post("remember");
                    if ($this->form_validation->run() === false) {

                     }else{
                        echo " logged in";// validation ok
                             $loginID = $this->input->post("login");
                             $pass = $this->input->post("password");
                             $remember = $this->input->post("remember");
                             //echo $loginID;
             if ($this->tank_auth->login(
                    $loginID,
                    $pass,
                    $remember,
                    $data['login_by_username'],
                    $data['login_by_email'])) {                             // success
                echo "success";
                redirect($redir);

            } else {
                $errors = $this->tank_auth->get_error_message();
                                    //echo "error";
                if (isset($errors['banned'])) {                             // banned user
                    $this->_show_message($this->lang->line('auth_message_banned').' '.$errors['banned']);

                } elseif (isset($errors['not_activated'])) {                // not activated user
                    redirect('/auth/send_again/');

                } else {                                                    // fail
                    foreach ($errors as $k => $v)   $data['errors'][$k] = $this->lang->line($v);
                }
            }

                    }
.....

对不起,长代码请帮助我。

4

1 回答 1

0

我没有看到你的构造函数中加载了库

public function __construct()
  {
     parent :: __construct();   
     $this->load->helper('url');
     $this->load->helper('cookie');
          //load the validation library
     $this->load->library('form_validation');
     $this->load->library("pagination");
  }
于 2013-02-13T08:06:18.577 回答