php - show detail product in online shop (codeigniter) -


i build online shop using codeigniter. have product catalogs. when user clicks each catalog, must show detailed information in view. but, have no idea on suppose do.

can give me example code, mean code in controller , model.

this view enter image description here

public function detail($page = 'detail') {   $data['title'] = ucfirst($page);    $this->cart_model->test($id);   $data['produk'] = $this->cart_model->test($id);   print_r($data['produk']);die();    $this->load->view('user/templates/header', $data);   $this->load->view('user/templates/navigation', $data);   $this->load->view('user/pages/' . $page, $data);   $this->load->view('user/templates/footer', $data); } 

my model

public function test($id) {   $query = $this->db->query('select * produk id_produk = ' . $id);   return $query->result_array(); } 

this view

<?php foreach ($produk $data): ?>  <div class="col-lg-4 col-md-4 col-sm-4">   <div class="images">     <a href="" class="img-responsive"><img src="/sjpro/asset/user/img/produk<?php echo $data['gambar'];?>"></a>   </div> </div>  <div class="col-lg-8 col-md-4 col-sm-4">    <h3><?php echo $data['nama_produk']?></h3>   <div class="price-detail">harga <span class="price-detail-color"><?php echo $data['harga_produk']?></span></div>    <span class="label label-success"><?php echo $data['status_produk']?></span>   <div class="well well-lg">     <form action="" class="form-horizontal">        <div class="form-group">         <label class="col-lg-2 control-label">jumlah</label>         <div class="col-lg-3">           <input type="number" step="1" min="1" name="quantity" value="1" class="form-control" size="2">         </div>         <button type="button" class="btn btn-success btn-lg pull-right" data-toggle="modal" data-target="#modal-beli">beli</button>       </div>      </form>   </div> 

enter image description here

if need product user select use <a> tag product id. <a href="<?php echo base_url()?>index.php/controller/function(preview)/<?php echo $data['id']?>">.

so function know product selected.

<a href="<?php echo base_url()?>index.php/controller/function(preview)/<?php echo $data['id']?>">         <div class="col-lg-4 col-md-4 col-sm-4">             <div class="images">                 <a href="" class="img-responsive"><img src="/sjpro/asset/user/img/produk<?php echo $data['gambar'];?>"></a>             </div>         </div>          <div class="col-lg-8 col-md-4 col-sm-4">              <h3><?php echo $data['nama_produk']?></h3>             <div class="price-detail">harga <span class="price-detail-color"><?php echo $data['harga_produk']?></span></div>             <span class="label label-success"><?php echo $data['status_produk']?></span>             <div class="well well-lg">                 <form action="" class="form-horizontal">                      <div class="form-group">                         <label class="col-lg-2 control-label">jumlah</label>                         <div class="col-lg-3">                             <input type="number" step="1" min="1" name="quantity" value="1" class="form-control" size="2">                         </div>                         <button type="button" class="btn btn-success btn-lg pull-right" data-toggle="modal" data-target="#modal-beli">beli</button>                     </div>                  </form>             </div>         </div>     </a> 

then catch tour controller

public function preview($id)//this know 1 parameter come {     $data['details']=$this-->your_model_name->get_details($id);//passing product id details of product  } 

in model

this select details form id passed model ($id)

public function get_details($id)     {         $query = $this->db->query("select * product id='$id'");         $result = $query->result_array();         return $result; //return object array     } 

in view

foreach ($details $details_new)  {     # code...  //you can use own style dives , usual  } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -