【问题标题】:how to pass data array in redirect method using codeigniter如何使用codeigniter在重定向方法中传递数据数组
【发布时间】:2015-03-19 19:45:21
【问题描述】:

控制器 --

  public function add_to_cart($id,$quantity){
            $this->load->model("getdb");
            $this->load->model('shops_model');
            $ins=TRUE;
            $product1= $this->getdb->Product($id);
            $price1 = $quantity/$product1[0]->min_quantity;
            foreach ($this->cart->contents() as $items) {
                if($items['id']==$id){
                    $ins=FALSE;
                $data = array(  
              'rowid'    => $items['rowid'],
               'id'      => $id,
               'price'   => $product1[0]->selling_price*$price1,
               'name'    => $product1[0]->product_name,
               'options' => array('image' =>$product1[0]->image1, 'unit' => $product1[0]->unit, 'quantity' => $quantity)
            );
        $this->cart->update($data);
            }
        }if($ins){
        $data = array(
               'id'      => $id,
               'qty'     => 1,enter code here
               'price'   => $product1[0]->selling_price*$price1,
               'name'    => $product1[0]->product_name,
               'options' => array('image' =>$product1[0]->image1, 'unit' => $product1[0]->unit, 'quantity' => $quantity)
            );
        $this->cart->insert($data);
        }
        $data['shops_id_data']= $this->shops_model->getshopiddata($id);
        $a = end(end($data['shops_id_data']));
        $data['shops_data']= $this->shops_model->getshopdata($a);
        redirect('Shops/shop_page');
    }

在这里,我想在 shop_page 方法上重定向,并且我想使用重定向方法在 shop_page 上传递 $data['shop_data] 数组,而不使用 $this->>load->view('shop_page',$data) .. ..那么它怎么可能..

【问题讨论】:

  • 我不知道这是可能的。 redirect() 无法传递参数,因为页面或控制器已更改。为什么不在商店页面中创建 $data['shop_data']?

标签: php codeigniter


【解决方案1】:

我在我的 codeigniter 安装中使用 HMVC。为此,我会使用类似

$this->load->module("Shops/shop");
$this->Shops->shop_page($data);

这篇文章帮助了我https://stackoverflow.com/a/14960794/501827

如果您不使用 HMVC,不确定这是否可行,但一些谷歌搜索可能会填补空白。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-04
    • 2020-09-29
    • 2022-08-05
    • 2021-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多