doulong4169 2014-08-22 22: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-22 23: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'));
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部