【发布时间】: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