我遇到会话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');
}
}
}
显示消息我在视图“login”中执行此操作:
<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的版本?
答案 0 :(得分:0)
您是否加载了session
库。我认为默认情况下不会加载session
库。
在调用session
或在flashdata
constructor
库
$this->load->library('session');
或将会话库添加到config/autoload.php