如何使用codeigniter flash变量? [英] How to use codeigniter flash variable?
问题描述
我基本上想要:
在CodeIgniter中添加一个问题数据库重定向用户返回页面显示成功弹出消息您的问题已创建
到目前为止,我可以将类别成功添加到db和用户输入验证正确,只有事情是我不知道如何创建弹出成功消息。 (我不想加载成功视图),只是重定向回他们来自的地方,并在顶部角落显示小消息或某事。
是闪存数据正确的方法?
控制器: -
$ create_data = $ this-> input-> post();
if(isset($ create_data ['question'])){
$ this-> load-> model('Test_model','test');
$ insert_status = $ this-> test-> insertQuestions($ create_data ['question']);
if($ insert_status){
echoRecord Inserted;
}
else {
echoInsertion Failed;
}
}
$ this-> layout-> view('test / create');
Flash数据听起来像往常一样。你可以这样做:
if($ insert_status){
$ notification =Record Inserted;
} else {
$ notification =Insertion Failed;
}
$ this-> session-> set_flashdata('notification',$ notification);
redirect('controller / method','refresh');
然后使用
$ this-> session-> flashdata('notification');
手册是此类信息的宝贵来源。
m struggling with Flash Data in CodeIgniter.
I basically want to:
add a question to a database redirect user back to a page show a success pop-up message "Your question has been created"
So far I can add the category successfully to the db and the user input is validated correctly, only thing is I don't know how to create the pop up success message. (I don't want to load a success view), just redirect back to where they came from and show small message in the top corner or something.
Is flash data the right way to go?
Controller:-
$create_data = $this->input->post();
if(isset($create_data['question'])){
$this->load->model('Test_model', 'test');
$insert_status = $this->test->insertQuestions($create_data['question']);
if($insert_status){
echo "Record Inserted";
}
else{
echo "Insertion Failed";
}
}
$this->layout->view('test/create');
Flash data sounds like the way to go. You could do something like this:
if($insert_status){
$notification = "Record Inserted";
} else {
$notification = "Insertion Failed";
}
$this->session->set_flashdata('notification', $notification);
redirect('controller/method','refresh');
Then access it with
$this->session->flashdata('notification');
The manual is an invaluable source for this kind of information.
这篇关于如何使用codeigniter flash变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!