我正在使用CI_Session类的this扩展名。使用TW Bootstrap创建闪存数据并设置样式。但是,当我将“成功”消息传递给视图时,它根本就没有加载。
我运气好,但没有喜悦。
我的控制器看起来像这样..
// Set form Validation
$this->form_validation->set_rules('title', 'Title', 'required|trim|is_unique[films.title]');
if($this->form_validation->run() == FALSE)
{
$data['page_title'] = 'Add New DVD';
$this->load->view('_partials/_header', $data);
$this->load->view('_partials/_menu');
$data['genres'] = $this->genre_model->get_genres();
$data['classification'] = $this->classification_model->get_classifications();
$this->load->view('create', $data);
$this->load->view('_partials/_footer');
}
else
{
// Insert into DB
$film_data = array
(
'title' => $this->input->post('title'),
'genre_id' => $this->input->post('genre'),
'classification_id' => $this->input->post('classification')
);
$this->film_model->create($film_data);
$this->session->set_success_flashdata('feedback', 'Success message for client to see');
redirect('dvd');
我的观点是......
<?php $this->session->flashdata('feedback'); ?>
因此,当我向数据库插入一个新项目时,模型运行,重定向运行,但“set_success_flashdata”不运行。
MY_session库设置为根据CI的默认配置自动加载。
如何让这个该死的Flash消息显示:(?
答案 0 :(得分:9)
set_success_flashdata
不是set_flashdata
。
控制器更改:
$this->session->set_flashdata('feedback', 'Success message for client to see');
视图就是这样:
echo $this->session->flashdata('feedback');
希望这会对你有所帮助。谢谢!
答案 1 :(得分:1)
虽然我没有看到这个特定扩展的重点,但答案很简单。
您没有回应会话库中的数据。
回复flashdata的正确方法是这样的:
<?php echo $this->session->flashdata('feedback'); ?>