在控制器注册中
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>
我无法展示&#34;您已经使用goole注册了。您将被重定向到主页。&#34;在视图上的消息,我测试了keep_flashdata和set_flashdata。
还有其他方法吗?如何在重定向和调用视图之间传递flash消息
答案 0 :(得分:2)
控制器更改:
$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'); ?>
希望这会对你有所帮助。谢谢!
答案 1 :(得分:0)
试试这个。
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设置它;)
答案 2 :(得分:0)
//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'); ?>