私はユーザーがウェブサイトに商品を追加できるようにウェブサイトを作っています。今私は製品の詳細ページに取り組んでいます。すべてがうまく動作し、製品のすべての詳細がエコーされています。しかし今、私はボタンを作ろうとしています。そのボタンをクリックすると、 'cadeaupagina_ontvanger'という名前の新しいビューページにリンクする必要があります。また、製品をコピーしてそのビューページに貼り付ける必要があります。 CodeIgniterにこの関数を書く方法がわかりません 誰かが私を助けてくれますか?商品をCodeIgniterの別のビューページにコピー
これは、詳細ページからボタンです:
<a href="<?php echo base_url() . 'Product/cadeaupagina_ontvangen/'.$product['user_id'];?>"> <button type="button" class="btn btn-default">Ik wil dit cadeau!</button></a>
コントローラの機能の詳細:
public function details($product_id)
{
//load the Product_model
$this->load->model('Product_model');
//call function getdata in de Product_model
$data['userdetail_list'] = $this->Product_model->getdata();
$this->session->set_userdata("product_id", $product_id);
//get product details
$data['product'] = $this->Product_model->get_product_details($product_id);
$data['products'] = $this->Product_model->selectProducts();
//laad view
$data['main_content'] = 'details';
$this->load->view('details',$data);
}
コントローラ機能cadeaupagina_ontvangen:
public function cadeaupagina_ontvangen($product_id) {
$this->load->model('Product_model');
//call function getdata in de Product_model
$data['userdetail_list'] = $this->Product_model->getdata();
// get product details
// if you want to pass data by url last param than use this
if(!empty($product_id)){
$data['product'] = $this->Product_model->get_product_details($product_id);
}
//if you want to pass data in session than use this
//get session in current controller
$product_id = $this->session->userdata("product_id");
if(!empty($product_id)){
$data['product'] = $this->Product_model->get_product_details($product_id);
}
$data['products'] = $this->Product_model->selectProducts();
//laad view
$data['main_content'] = 'ontvangen_cadeaus';
$this->load->view('cadeaupagina_ontvanger',$data);
}
cadeaupagina_ontvangerは私がしたいビューのページです同じ製品を貼り付ける。 Product_modelで
モデル関数:
public function getdata()
{
$this->db->select('*');
$this->db->from('users');
$this->db->join('products','products.user_id = users.user_id');
$query = $this->db->get();
if($query->num_rows()>0)
{
return $query->result_array();
}
}
public function selectProducts()
{
$query= $this->db->query("SELECT * FROM products");
$result = $query->result_array();
return $result;
}
/** Met deze functie kan je de product details ophalen via de $product_id **/
public function get_product_details($product_id)
{
$arrReturn = array();
$this->db->select('*');
$this->db->from('products');
$this->db->where('product_id', $product_id);
$query = $this->db->get();
$result = $query->result_array();
if (!empty($result)) {
$arrReturn = $result[0];
}
return $arrReturn;
}
を追加このコントローラの以前のコントローラメソッド。 –
私の質問を編集し、以前のコントローラの機能を表示する – Learningprogrammingphp44
詳細のコントローラ機能をチェックしました – Learningprogrammingphp44