doushun1870 2015-01-31 05:20
浏览 35

Codeigniter:set_message无法工作

this is my controller code:

public function login_validation(){

        $this->load->library('form_validation');
        $this->load->model('model_users');

        $this->form_validation->set_rules('username', 'Username', 'required|trim|alpha_numeric|xss_clean|strip_tags');
        $this->form_validation->set_rules('password', 'Password', 'required|trim|xss_clean|strip_tags');

        if ($this->form_validation->run()){
            if ($this->model_users->can_log_in()){
                $data = array(
                    'username' => $this->input->post('username'),
                    'password' => $this->input->post('password')
                );

                if($this->model_users->get_status($data['username'])){
                    $data = array(
                    'username' => $this->input->post('username'),
                    'privilege' => 'member',
                    'is_logged_in' => 1
                    );
                    $this->session->set_userdata($data);
                    redirect('member');
                } else {
                    $data = array(
                    'username' => $this->input->post('username'),
                    'privilege' => 'admin',
                    'is_logged_in' => 1
                    );
                    $this->session->set_userdata($data);
                    redirect('admin');
                }
            } else {
                $this->form_validation->set_message('login_validation', 'Incorrect username/password.');
            }
        } else {
            $this->login();
        }

May i know why does the $this->form_validation->set_message('login_validation', 'Incorrect username/password.'); doesn't work when the user credentials are entered incorrectly? I tried it and the result was that it will result an empty blank page.

  • 写回答

1条回答 默认 最新

  • doujingdai5521 2015-01-31 05:29
    关注

    You can view all errors with:

    $message = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');

    var_dump($message);

    And you need activate the log-

    Edit the file: application/config/config.php - Full/All error reporting, set it to 4. - For only ERRORS,set it to 1. - For ERRORS and WARNINGS/DEBUG,set it to 2.

    Then Set CodeIgniter log directory to be writable by the server, use command:

    chmod 777 /logs/

    Now you are ready to get logs in your log file.That from command line you can do as:

    tail -f /application/logs/log-YYYY-MM-DD.php

    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程