【问题标题】:Validation flashdata error is not displaying in CodeIgniterCodeIgniter 中未显示验证 flashdata 错误
【发布时间】:2017-10-13 12:10:59
【问题描述】:

这是我在控制器中的登录方法,这里我正在为验证错误设置一个闪烁消息 -

public function login(){
    $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[3]');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[3]');

    if($this->form_validation->run() == FALSE){
        $data = array(
          'errors' => validation_errors()
        );
        $this->session->set_flashdata($data);
        redirect('home');
    }
}

这里是显示这些错误的代码 -

<?php if($this->session->flashdata('errors')): ?>
    <?php echo $this->session->flashdata('errors');?>

<?php endif; ?>

不知道怎么回事,没有显示错误信息。

【问题讨论】:

  • 像这样尝试 $this->session->set_flashdata('errors', validation_errors());作为单个项目而不是数组。
  • 再次检查文档。您必须加载视图,而不是在表单失败时重定向。设置会话后在 else 块中进行重定向。

标签: php codeigniter session flash-message


【解决方案1】:

我希望完成这个过程

if($this->form_validation->run() == FALSE){
    $this->session->set_flashdata('name','Your message');
    redirect('home');
}
<?php if($this->session->flashdata('name')): ?>
<?php echo $this->session->flashdata('name');?>    
<?php endif; ?>

【讨论】:

    【解决方案2】:

    它放置在控制器中

    if ($this->form_validation->run() == FALSE) {       
    $errors = validation_errors();
               $this->session->set_flashdata('form_error', $errors);
               $this->load->view('Your View page');
    }
    

    它放置在您的查看页面中

    <?php if($this->session->flashdata('form_error')): ?>
        <?php echo $this->session->flashdata('form_error');?>
    
    <?php endif; ?>
    

    希望对你有所帮助..!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-11
      • 1970-01-01
      • 1970-01-01
      • 2014-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多