【问题标题】:how to pass an valuable with redirect?如何通过重定向传递有价值的信息?
【发布时间】:2012-01-21 00:06:37
【问题描述】:

在用户授权失败后,我无法尝试传递有价值的东西。我想将 $error 传递给欢迎控制器,但不确定如何。请帮忙。谢谢你。

  private function _user_check()
            {
                 //after form validation, I pass username and password to the model
                    $this->load->model('user_query');
                    $result=$this->user_query->query($this->input->post('username'),$this->
                    input->post('password'));

                    if($result)
                {
                    redirect('main');

                }else{
                    // I am not sure how to pass this error message to my welcome controller
                    $data['error']='Please check your username or password';
                    redirect('welcome');
                }


        }

【问题讨论】:

    标签: php codeigniter http-redirect


    【解决方案1】:

    在重定向函数中,您没有提供完整的 URL,因此 CI 会将参数视为控制器的 URI 段。

    知道了这一点,你可能会有类似的东西:

    redirect('welcome/error/error_user_pass');
    

    并让正在传递的“error_user_pass”引用在您的 CI 项目中定义的错误常量。

    在你的 application/config/constants.php 文件中可能是这样的:

    define('error_user_pass', 'incorrect user or password, please check yo self!');
    

    然后在你的“欢迎”控制器中有这样的东西:

    class Welcome extends CI_Controller {
      public function error(){
        $errors = func_get_args();
        foreach( $errors as $error ){
          //echo error, or save it, or whatev
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-02-02
      • 1970-01-01
      • 2010-10-10
      • 2013-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多