【发布时间】:2014-11-28 01:33:54
【问题描述】:
我的会话 flashdata 有问题。永远不会显示包含会话的消息。我在页面上阅读了很多帖子。但我没有找到解决问题的方法
我有这条路线:
//index is a subfolder into the controllers folder
//user is a controller
$route['login'] = 'index/user/showLogin';
$route['do_login'] = 'index/user/doLogin';
$route['register'] = 'index/user/showRegister';
$route['do_register'] = 'index/user/doRegister';
user.php 控制器:
public function showRegister()
{
$this->template->set('title', 'test register');
$this->template->load('template', 'index/register', $data);
}
public function doRegister()
{
$this->form_validation->set_rules('email', 'Email', 'required|trim|max_length[30]|xss_clean|valid_email|is_unique[users.email]|');
$this->form_validation->set_rules('password', 'Password', 'required|trim|min_length[6]|max_length[20]|xss_clean|alpha_dash');
$this->form_validation->set_rules('rrpassword', 'Re Password', 'required|trim|min_length[6]|max_length[20]|xss_clean|matches[password]|alpha_dash');
if($this->form_validation->run() == FALSE)
{
$this->showRegister();
}
else
{
$email = $this->input->post('email');
$pass = $this->input->post('password');
$password = $this->bcrypt->hash_password($pass);
// check if the password was encrypted
if ($this->bcrypt->check_password($pass, $password))
{
$data =array(
'email' => $email,
'password' => $password,
);
$insert = $this->user_model->register($data);
if(!$insert)
{
echo 'error';
}
$this->session->set_flashdata('info', 'registered');
redirect('login', 'refresh');
}
else
{
$this->session->set_flashdata('info', 'Oops.. error...');
redirect(base_url('login'), 'refresh');
}
}
}
为了显示消息,我在“登录”视图中执行此操作:
<div class="alert alert-info alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
Test: <?php echo $this->session->flashdata('info'); ?>
</div>
但永远不会打印消息。我试过这个:
$this->session->set_flashdata('info', 'test......');
$this->session->keep_flashdata('info');
redirect('login', 'refresh');
但不起作用。还将 favicon.ico 添加到根文件夹,但不起作用。几个小时前我正在尝试修复它。可能是PHP的版本?
【问题讨论】:
标签: php codeigniter session