doulong4169 2014-08-23 06:54
浏览 53
已采纳

如何在codeigniter中显示flashdata

Following is my view I am catching the data from the model and displaying on the view using flashdata in codeigniter

My Controller cart.php

 public function coupon(){
    for ($i = 0; $i <= $this->input->post("products_in_cart"); $i++) {

        if (!empty($this->input->post("coupn-" . $i))) {

            $couponname = $this->input->post("coupn-" . $i);
            $products_id = $this->input->post("product_id" . $i);

            $data = $this->home_model->getCoupon($couponname, $products_id);
            $data1 = 'hello';
            $info = array(
                "PromotioanlName" => $data->PromotionalName,
            );
        } else {

            $info = 'Thers in no value<br>';
        }



    }
    echo $this->session->set_flashdata('message', $info);
    redirect(site_url('cart'));
}

My view cart.php

 $message = $this->session->flashdata('message');
  print_r($message);

But my problem is that my data is overwritten by the next value

  • 写回答

1条回答 默认 最新

  • duanlian1320 2014-08-23 07:20
    关注

    in for loop, you have written if and in if, $info is an array and in else, $info is string!! Thus in loop when condition of if will be true, it'll be worked as an array and it'll be overwritten if condition will be true again in second recurs of loop!! And while condition false, it'll return string that will overwrite your array..

    Try by using, $info[] instead of $info.. May be it solved your problem..

    public function coupon(){
        for ($i = 0; $i <= $this->input->post("products_in_cart"); $i++) {
    
            if (!empty($this->input->post("coupn-" . $i))) {
    
                $couponname = $this->input->post("coupn-" . $i);
                $products_id = $this->input->post("product_id" . $i);
    
                $data = $this->home_model->getCoupon($couponname, $products_id);
                $data1 = 'hello';
                $info[] = array(
                    "PromotioanlName" => $data->PromotionalName,
                );
            } else {
    
                $info[] = 'Thers in no value<br>';
            }
    
    
    
        }
        echo $this->session->set_flashdata('message', $info);
        redirect(site_url('cart'));
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失