douxian5963 2017-02-24 00:41
浏览 51

codeigniter不显示重定向页面相同

I want when I add a product to the cart and reload the same page, but the problem did not this product.

The controller

public function detail()
 {              
      $data=array('title' =>'Ecommerce Online | Detail Product',
           'username'   => $this->session->userdata('id'),
           'categories' => $this->categories_model->get_categories(),
           'details'    => $this->categories_model->get_details($this->uri->segment(3)),
           'isi'        =>'member/detail');
      $this->load->view('template_home/wrapper',$data);
 }

function addtocart()
{                   
    if($this->cart_model->validate_add_cart_item() == TRUE){
        if($this->input->post('ajax') != '1'){
            redirect('member/detail/'. $this->uri->segment(3)); // this problem
        }else{
            echo 'true';
        }
        }
}

I add my models

function validate_add_cart_item()
{
        $id = $this->input->post('product_id'); 
        $cty = $this->input->post('quantity'); 

        $this->db->where('productID', $id);
        $query = $this->db->get('product', 1);

        if($query->num_rows > 0){

            foreach ($query->result() as $row)
            {
                $data = array(
                    'id'      => $id,
                    'qty'     => $cty,
                    'price'   => $row->price,
                    'name'    => $row->productName
                );

                $this->cart->insert($data); 

                return TRUE;
            }
        }else{
            return FALSE;
        }
    }

I add my view

<?php foreach ($details as $s) { ?>
    <div class="col-md-5">
        <div class="box text-center">
            <img src="<?php echo base_url('upload/'.$s->photo); ?>" width="150px" height="150px">
            <br><?php echo $s->productName; ?>
            <br><strong>Rp. <?php echo $s->price; ?></strong>
            <br>
            <?php echo form_open('member/add'); ?>
            <fieldset>
                <label>Quantity</label>
                <?php echo form_input('quantity', '1', 'maxlength="2"'); ?>
                <?php echo form_hidden('product_id', $s->productID); ?>
                <?php echo form_submit('add', 'Add'); ?>
            </fieldset>
            <?php echo form_close(); ?>
        </div>
    </div>
<?php } ?>

I want to such as this url: http://localhost/scientificwriting/member/detail/005 and the third segment url is id_product. Please help me thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 路易威登官网 里边的参数逆向
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
    • ¥50 需求一个up主付费课程
    • ¥20 模型在y分布之外的数据上预测能力不好如何解决
    • ¥15 processing提取音乐节奏
    • ¥15 gg加速器加速游戏时,提示不是x86架构
    • ¥15 python按要求编写程序
    • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入