无法在CodeIgniter中获取flashdata
这是我的控制器代码无法在CodeIgniter中获取flashdata,codeigniter,Codeigniter,这是我的控制器代码 function index() { echo $this->session->flashdata('message'); $this->load->view('categoryView'); } function delete() { $products = $this->item_model->get_category_id($category_id); if (count($products)) {
function index() {
echo $this->session->flashdata('message');
$this->load->view('categoryView');
}
function delete() {
$products = $this->item_model->get_category_id($category_id);
if (count($products)) {
$message = 'Category Name is used by the product. Please change them to another category!';
}
else {
$category_id = $this->product_category_model->delete($category_id);
$message = ($category_id) ? 'Category Deleted Successfully' : 'Failed to Delete Category';
}
$this->session->set_flashdata('message', $message);
redirect('category', 'refresh');
}
调用delete函数后,必须在同一控制器的index()函数中设置和检索flashdata的值,但我不能
Am还尝试了$this->session->keep_flashdata('message');在重定向到索引函数之前。但在索引函数中仍然没有得到任何值
还更改了$config['sess\u expire\u on\u close']=FALSE;to$config['sess\u expire\u on\u close']=TRUE;我仍然没有得到结果
我浪费了更多的时间(将近半天)。请任何人帮助检索codeigniter中的flas数据。有几种可能性: 1-检查浏览器cookie。查看它是否允许cookie,或者是否有任何其他扩展正在介入 2-
Refresh
可能不会向浏览器发送新请求(这意味着新的URL)。尝试另一个控制器,看看是否有任何变化
3-使用硬编码值而不是变量对
set_flashdata()
进行硬编码<代码>设置flashdata(“消息”、“谢谢”)代码>在CodeingEditor中,您不能在控制器中回显任何内容
您必须在$this->session->flashdata('message')中进行设置代码>视图中的文件不在控制器的index()函数中
通过放置$this->session->flashdata('message')重试代码>在“categoryView”文件中,您要在其中显示flash消息。您可以尝试:
function set_flashdata_notification($notify_type, $msg, $error_code = null)
{
$ci =& get_instance();
$flashdata_data = set_notification_array($notify_type, $msg, $error_code);
$ci->session->set_flashdata($flashdata_data);
}
function delete() {
$products = $this->item_model->get_category_id($category_id);
if (count($products)) {
set_flashdata_notification('Category Name is used by the product.','Please change them to another category!');
redirect('path_to_view/view','refresh');
}
抱歉,您是否已自动加载会话?因此索引文件中的回音不起任何作用?我已自动加载会话,并且已使用会话类,该类工作正常,但闪存数据不工作是的。索引函数中的回显不显示任何内容您可以回显任何内容。谁说的?只需回显它就可以看到它被回显。但是这样做不是一个好的做法。set_flashdata_notification()和set_flashdata()之间的区别是什么?如果我使用set_flashdata_notification(),则会显示未定义的函数错误。在set_flashdata_notification()的最后,通过set_flashdata()设置flashdata。对于该函数,数组作为数据权限传递。为什么我们需要这样做,相反,我们可以直接使用set_flashdata()。我不想分享你的想法,谢谢你宝贵的回答。就像你说的那样,我作为控制员对控制员受到了考验。那很好。但我试图在同一个控制器中获取flasdata意味着无法获取?请分享你的想法