控制器内注册
function signup() {
if('user already exists') {
$this->session->flashdata('flsh_msg', 'You have already signed up using goole. you will be redirected to home page.');
redirect('signup/signup/show_message');
}
}
在同一控制器中显示消息,只是为了显示视图
function show_message()
{
$this->load->view('header/header');
$this->load->view('signup/signup_message');
$this->load->view('footer/footer');
}
视图文件:
<div class="alert alert-success">
<?php echo $this->session->flashdata('flsh_msg'); ?>
</div>
我无法显示"你已经使用谷歌注册了。你将被重定向到主页。"查看消息时,我已经测试了keep_flashdata和set_flashdata。
有其他方法可以做到这一点吗?如何在重定向和调用视图之间传递flash消息
控制器变更:
$this->session->set_flashdata('flsh_msg', 'You have already signed up using goole. you will be redirected to home page.');
视图原样:
<?php echo $this->session->flashdata('flsh_msg'); ?>
希望这对你有帮助。谢谢
试试这个。
function signup() {
if('user already exists') {
$this->session->set_flashdata('flsh_msg', 'You have already signed up using goole. you will be redirected to home page.');
redirect('signup/signup/show_message');
}
}
flashdata的设置功能是set_flashdata,而不仅仅是flashdata。。只有flashdata("flsh_msg")会获得该字符串,但是set_flashdata设置了它;)
//Controller
$this->session->set_flashdata('flsh_msg', 'You have already signed up using goole. you will be redirected to home page.');
redirect('signup/signup/show_message');
//View
<?= $this->session->flashdata('flsh_msg'); ?>
$this->session->set_flashdata('flsh_msg', 'You have already signed up using goole. you will be redirected to home page.');