Pemograman Web Enterprise 6 Model
Pemograman Web Enterprise 6 Model
Pemogramman
Web Enterprise
2025
6 87001
Abstract Kompetensi
Mata kuliah dasar keahlian Web Programming Mahasiswa berkemampuan membangun dasar logika
ditunjang dengan matakuliah Web Pemrograming
pemrograman dan pemecahan masalah sederhana.
Enterprise untu k membangun kemampuan dasar
logika pemrograman dan pemecahan masalah
sederhana..
MODEL
Setelah kita belajar tentang Controller dan View, berikutnya kita akan belajar tentang Model dan database.
Model adalah kode yang bertugas untuk membuat pemodelan data. Kadang juga dipakai untuk pemodelan logika bisnis.
Model bisa mengakses data dari Database dan juga sumber lainnya. Seperti API pihak ketiga.
Intinya:
CREATE DATABASE IF NOT EXISTS `mercubuana` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016
USE `mercubuana`;
Unremark # , pastikan user dan password ,dan configurasi yang lainnya sudah benar
<?php
namespace App\Models;
use CodeIgniter\Model;
// // Dates
// protected $useTimestamps = false;
// protected $dateFormat = 'datetime';
// protected $createdField = 'created_at';
// protected $updatedField = 'updated_at';
// protected $deletedField = 'deleted_at';
// // Validation
// protected $validationRules = [];
// protected $validationMessages = [];
// protected $skipValidation = false;
// protected $cleanValidationRules = true;
// // Callbacks
// protected $allowCallbacks = true;
// protected $beforeInsert = [];
// protected $afterInsert = [];
// protected $beforeUpdate = [];
// protected $afterUpdate = [];
// protected $beforeFind = [];
// protected $afterFind = [];
// protected $beforeDelete = [];
// protected $afterDelete = [];
}
<?php
namespace App\Controllers;
use App\Controllers\BaseController;
use CodeIgniter\HTTP\ResponseInterface;
use App\Models\MahasiswaModel;
$mahasiswaModel=new MahasiswaModel();
$data['mahasiswa']=$mahasiswaModel->findAll();
return view('mahasiswa/index',$data);
//
return view('mahasiswa/index');
menjadi
return view('mahasiswa/index',$data);
$data adalah variable hasil dari database table mahasiswa yang akan ditampilkan pada view
<body>
</div>
<thead class='thead-dark'>
<tr>
<th>No</th>
<th>Nim</th>
<th>Nama</th>
<th>Email</th>
<th>Jurusan</th>
<th>Alamat</th>
<th>Province</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
<?php
?>
<tr>
<td>
</td>
</tr>
<?php
endforeach;
?>
</tbody>
</table>
</div>
</body>
Perhatikan saat mengambil data dengan menggunakan looping foreach karena datanya bisa lebih dari 1 sbb:
<?php
?>
Hasilnya Sbb:
DAFTAR PUSTAKA
DAFTAR PUSTAKA
1. abdkhaliq.com
2. https://codeigniter.com/user_guide/incoming/controllers.html
3. https://www.petanikode.com/codeigniter4-controller/ PetaniKode