Bagaimana cara memasukkan data dari view ke model di codeigniter?

Jadi,di Model_invoice pada Codeigniter ini saya ingin membuat total bayar dengan mengambil data $grant_total dari View( Pembayaran.php )

<?php

class Model_invoice extends CI_Model{
	public function index()
	{
		date_default_timezone_set('Asia/Jakarta');
		$nama = $this->input->post('nama');
		$alamat = $this->input->post('alamat');
		$no_telp=$this->input->post('no_telp');
$total_byr = [code..]

		$invoice = array(
			'nama' => $nama,
			'alamat' => $alamat,
			'no_telp' => $no_telp,
			'tgl_pesan' => date('Y-m-d H:i:s'),
			'batas_bayar' => date('Y-m-d H:i:s',mktime(date('H'),date('i'),date('s'),date('m'),date('d') + 1,date('Y'))),

'total_bayar' => 	[ code...]	);

		$this->db->insert('tb_invoice',$invoice);
		$id_invoice = $this->db->insert_id();
		$id_user = $this->db->insert_id();
		foreach ($this->cart->contents() as $item){
			$data = array(
				'id_invoice'	=> $id_invoice,
				'id_user'       => $id_user,
				'id_brg'   		=> $item['id'],
				'nama_brg' 		=> $item['name'],
				'jumlah' 		=> $item['qty'],
				'harga' 		=> $item['price'],
			);
			$this->db->insert('tb_pesanan',$data);
		}
		return TRUE;
	}

	public function tampil_data()
	{
		$result = $this->db->get('tb_invoice');
		if($result->num_rows() > 0){
			return $result->result();
		}else{
			return false;
		}
	}

	public function ambil_id_invoice($id_invoice)
	{
		$result =$this->db->where('id',$id_invoice)->limit(1)->get('tb_invoice');
		if($result->num_rows() > 0){
			return $result->row();
		}else{
			return false;
		}
	}

	public function ambil_id_pesanan($id_invoice)
	{
		$result =$this->db->where('id_invoice',$id_invoice)->get('tb_pesanan');
		if($result->num_rows() > 0){
			return $result->result();
		}else{
			return false;
		}
	}

}

View( Pembayaran.php )

<div class="container-fluid">
	<div class="row">
		<div class="col-md-2"></div>
		<div class="col-md-8">
		 <div class="btn btn-sm btn-info">
		 	<?php
		 	$grand_total =0;
			if($keranjang = $this->cart->contents())
		 	{
		 		foreach($keranjang as $item)
		 		{
		 		$grand_total = $grand_total + $item['subtotal'];
		 	}
		 	echo "Total Belanja Anda: Rp. ".number_format($grand_total,0,',','.');
		  ?>
		 </div><br><br>

		 <h3>Input Alamat Pengiriman dan Pembayaran</h3>

		 <form action="<?= base_url('dashboard/proses_pesanan'); ?>"method="post">

		 	<div class="form-group">
		 		<label>Nama Lengkap</label>
		 		<input type="text" name="nama" placeholder="Nama Lengkap Anda" class="form-control">
		 	</div>

		 	<div class="form-group">
		 		<label>Alamat Lengkap</label>
		 		<input type="text" name="alamat" placeholder="Alamat Lengkap Anda" class="form-control">
		 	</div>

		 	<div class="form-group">
		 		<label>No.Telepon</label>
		 		<input type="text" name="no_telp" placeholder="No.Telepon Anda" class="form-control">
		 	</div>

		 	<button type="submit" class="btn btn-sm btn-info m-5">Pesan</button>

		 </form>

		 <?php
		} else
		{
			echo "Keranjang Belanja Anda Masih Kosong";
		 }
			?>
		</div>

		<div class="col-md-2"></div>
	</div>
</div>

avatar laurentellyzabeth
@laurentellyzabeth

14 Kontribusi 0 Poin

Diperbarui 2 tahun yang lalu

1 Jawaban:

<div>Untuk mengambil data dari view harus lewat controller nah dari method di controller ini yang memanggil modelnya.<br><br>ref CI 3 :&nbsp;<a href="http://codeigniter.com/userguide3/tutorial/create_news_items.html">http://codeigniter.com/userguide3/tutorial/create_news_items.html</a><br><br>ref CI 4:&nbsp;<a href="https://codeigniter.com/user_guide/tutorial/create_news_items.html">https://codeigniter.com/user_guide/tutorial/create_news_items.html</a></div>

avatar billiyagi
@billiyagi

18 Kontribusi 7 Poin

Dipost 2 tahun yang lalu

Tanggapan

You really take your time in writing this article and they are clearly detailed as the articles on the site <a href="www.rootsanalysis.com">rootsanalysis</a>. Please check the report <a href="https://www.rootsanalysis.com/reports/protein-design-and-engineering-market.html">Protein design</a>

Login untuk ikut Jawaban