Modul Pelangggaran
Modul Pelangggaran
B. TOMBOL DETAIL
C. TAMBAH DATA/ INSERT DATA
Langkah Langkah yang dilakukan untuk menambahkan data adalah sebagai
berikut :
1. Tambahkan tombol tambah data pada file
views/Pelanggaran/siswa.php kitab bisa copy dan tombol boostrap atau
ambil nama class dari button boostrap,seperti tambilan berikut :
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-
scale=1">
<title>SMK N 1 KINALI</title>
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstra
p.min.css" rel="stylesheet"
integrity="sha384-
T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
crossorigin="anonymous">
<style>
body {
background-color: #f8f9fa;
color: #343a40;
font-family: 'Arial', sans-serif;
}
header {
background-color: #007bff;
color: #ffffff;
padding: 20px;
text-align: center;
}
h1 {
margin-bottom: 0;
font-size: 2.5rem;
font-weight: bold;
}
p {
font-size: 1.2rem;
margin-bottom: 0;
}
nav {
background-color: #343a40;
}
.navbar-nav .nav-link {
color: #ffffff;
}
.navbar-nav .nav-link:hover {
color: #007bff;
}
img {
max-width: 100%;
height: auto;
}
</style>
</head>
<body>
<header>
<img src="/img/logo.png" alt="SMK N 1 KINALI Logo"
class="img-fluid">
<h1>Welcome to SMK N 1 KINALI</h1>
<p>Jln. Teuku Umar Padang Kuranji KM.1 Kapunduang</p>
<?php
echo "<p>Today is " . date("Y-m-d") . "</p>";
?>
</header>
<nav class="navbar navbar-expand-lg navbar-dark">
<div class="container">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page"
href="/Pelanggaran">Home</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="/Pelanggaran/profile">Profil</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="/Pelanggaran/siswa">Pelanggaran</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="/Pelanggaran/kontak">Kontak</a>
</li>
</ul>
</div>
</nav>
2. Views/Layout/footer.php
<footer class="bg-primary text-white text-center py-3">
3. Views/Layout/kontak.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Contact Information - SMK Negeri 1 Kinali</title>
<style>
section {
max-width: 600px;
margin: 20px auto;
padding: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 10px;
}
</style>
</head>
<body>
<h1 class="text-center text-primary mt-5">SMK Negeri 1
Kinali</h1>
<section>
<h2>Contact Information</h2>
<p>Email: <a
href="mailto:[email protected]">[email protected]</a></p>
<p>Phone: 0813 63 368650</p>
<p>Website : <a href="http://www.smkn1kinali.sch.id"
target="_blank">www.smkn1kinali.sch.id</a></p>
<h2>Social Media</h2>
<p>Instagram: <a
href="https://www.instagram.com/smknegeri1kinali/?
utm_source=ig_web_button_share_sheet&igshid=OGQ5ZDc2ODk2ZA=="
target="_blank">SMKNegeri1Kinali</a></p>
</section>
<br>
<br>
<br>
<br>
4. Views/Layout/profile.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Profil SMK Negeri 1 Kinali</title>
<style>
section {
max-width: 600px;
margin: 20px auto;
padding: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 10px;
}
</style>
</head>
<body>
<center><h2>Profil SMK Negeri 1 Kinali</h2></center>
<section>
<h2>Informasi Sekolah</h2>
<p>NSS: 3210 8105 001</p>
<p>Alamat Sekolah : Jl. Teuku Umar KM.1 Kapundung Padang
Kuranji</p>
<p>Kanagarian : Kinali</p>
<p>Kecamatan : Kinali</p>
<p>Kabupaten : Pasaman Barat</p>
<p>Kode Pos : 26367</p>
<p>Telepon / HP : 0813 63 368650</p>
<h2>Website dan Kontak</h2>
<p>Website : <a href="http://www.smkn1kinali.sch.id"
target="_blank">www.smkn1kinali.sch.id</a></p>
<p>Email : [email protected]</p>
<h2>Bidang Keahlian</h2>
<p>Kelompok Teknologi Industri</p>
<p>Bidang Keahlian:</p>
<ul>
<li>Teknik Audio-Video</li>
<li>Teknik Komputer dan Jaringan</li>
<li>Teknik Multimedia</li>
<li>Administrasi Perkantoran</li>
<li>Akuntansi</li>
<li>Teknik dan Bisnis Sepeda Motor</li>
</ul>
</section>
</body>
</html>
5. Views/Pelanggaran/detail.php
<div class="container">
6. Views/Pelanggaran/editdata.php
<div class="container">
<div class="row">
<div class="col">
<h1 class="mt-3">Formulir Edit Data Pelanggaran
Siswa</h1>
7. Views/Pelanggaran/index.php
. <div class="container">
<div class="row">
<div class="col">
<h1 class="text-center text-primary mt-5">
Selamat Datang di Aplikasi Pelanggaran Siswa
</h1>
<div class="card bg-dark text-danger mt-4">
<img src="img/sekolah.png" class="card-img"
alt="Sekolah Image">
<div class="card-img-overlay">
</div>
</div>
</div>
</div>
</div>
8. Views/Pelanggaran/siswa.php
<div class="container">
<div class="row">
<div class="col"><br>
<a href="/Pelanggaran/tambahdata" class="btn btn-
primary">Tambahkan Siswa</a>
<a href="/Pelanggaran/tampilpel" class="btn btn-
primary">Laporan Pelanggaran</a>
<?php if (session()->getFlashdata('pesan')) : ?>
<div class="alert alert-success" role="alert">
<?= session()->getFlashdata('pesan') ; ?>
</div>
<?php endif; ?>
<?php if (session()->getFlashdata('error')) : ?>
<div class="alert alert-danger" role="alert">
<?= session()->getFlashdata('error') ; ?>
</div>
<?php endif; ?>
<h1> Daftar Siswa</h1>
<table class="table table-striped table-hover">
<thead>
<tr class="table-info">
<th scope="col">#</th>
<th scope="col">NIS</th>
<th scope="col">Nama</th>
<th scope="col">Kelas</th>
<th scope="col">Jenis Kelamin</th>
<th scope="col">Alamat</th>
<th scope="col">Detail</th>
</tr>
</thead>
<tbody>
<?php $no = 1; ?>
<?php foreach ($objek as $r) : ?>
<tr class="table-striper">
<th scope="row"><?= $no++; ?></th>
<td><?= $r['nis']; ?></td>
<td><?= $r['nama']; ?></td>
<td><?= $r['kelas']; ?></td>
<td><?= $r['j_k']; ?></td>
<td><?= $r['alamat']; ?></td>
<th scope="col">
<a class="btn btn-warning"
href="detail/<?=$r['nis']; ?>" role="button">Detail</a>
</th>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
9. Views/Pelanggaran/tambahdata.php
<div class="container">
<div class="row">
<div class="col">
<?php if (session()->getFlashdata('required')) : ?>
<div class="alert alert-success" role="alert">
<?= session()->getFlashdata('required'); ?>
</div>
<?php endif; ?>
<h1 class="mt-3">Formulir Isi Data Siswa</h1>
<form action="/Pelanggaran/savedata" method="POST">
10.Views/Pelanggaran/tampilpel.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Tampil Data Pelanggaran</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstr
ap.min.css">
</head>
<body>
<div class="container mt-4">
<h1>Tampil Data Pelanggaran</h1>
<table class="table table-striped">
<thead>
<tr>
<th>NIS</th>
<th>Nama</th>
<th>Kelas</th>
<th>Jenis Kelamin</th>
<th>Alamat</th>
<th>ID Jenis Pelanggaran</th>
<th>Nama Jenis Pelanggaran</th>
<th>Poin Pelanggaran</th>
<th>ID Pelanggaran</th>
<th>Tanggal Pelanggaran</th>
<th>Keterangan Pelanggaran</th>
</tr>
</thead>
<tbody>
<?php foreach ($objek as $data) : ?>
<tr>
<td><?= htmlspecialchars($data['nis']); ?
></td>
<td><?= htmlspecialchars($data['nama']);
?></td>
<td><?= htmlspecialchars($data['kelas']);
?></td>
<td><?= htmlspecialchars($data['j_k']); ?
></td>
<td><?=
htmlspecialchars($data['alamat']); ?></td>
<td><?=
htmlspecialchars($data['id_j_pel']); ?></td>
<td><?=
htmlspecialchars($data['n_j_pel']); ?></td>
<td><?= htmlspecialchars($data['poin']);
?></td>
<td><?=
htmlspecialchars($data['id_pel']); ?></td>
<td><?=
htmlspecialchars($data['tgl_pel']); ?></td>
<td><?= htmlspecialchars($data['ket']); ?
></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<a href="/Pelanggaran/siswa" class="btn btn-
success">Kembali ke Daftar Siswa</a>
</div>
</body>
</html>
namespace App\Models;
use CodeIgniter\Model;
class TpelanggaranModel extends Model
{
protected $table = 'siswa';
protected $primaryKey = 'nis';
protected $useAutoIncrement = false;
protected $allowedFields = ['nis', 'nama', 'kelas', 'j_k',
'alamat'];
public function getObjek($nis = false)
{
if ($nis === false) {
return $this->findAll();
}
return $query;
}
public function getSiswa($nis)
{
return $this->db->table('siswa')
->where('siswa.nis', $nis)
->get()
->getResult();
}
public function savePelanggaran($data)
{
return $this->db->table('pelanggaran')->insert($data);
}
public function saveJenisPelanggaran($data)
{
return $this->db->table('jenis_pelanggaran')->insert($data);
}
}
namespace App\Controllers;
use App\Models\TpelanggaranModel;
class Pelanggaran extends BaseController
{
protected $Objek;
public function __construct()
{
$this->Objek = new TpelanggaranModel();
}
public function index()
{
echo view('Layout/header');
echo view('Pelanggaran/index');
echo view('Layout/footer');
}
public function profile()
{
$data = [
'title' => 'Profile Penulis'
];
echo view('Layout/header', $data);
echo view('Layout/profile');
echo view('Layout/footer');
}
public function kontak()
{
echo view('Layout/header');
echo view('Layout/kontak');
echo view('Layout/footer');
}
public function savedata()
{
$siswaData = [
'nis' => $this->request->getVar('nis'),
'nama' => $this->request->getVar('nama'),
'kelas' => $this->request->getVar('kelas'),
'j_k' => $this->request->getVar('j_k'),
'alamat' => $this->request->getVar('alamat'),
];
$this->Objek->save($siswaData);
$nis = $this->request->getVar('nis');
$jenisPelanggaranData = [
'id_j_pel' => $this->request->getVar('id_j_pel'),
'n_j_pel' => $this->request->getVar('n_j_pel'),
'poin' => $this->request->getVar('poin'),
];
$this->Objek->saveJenisPelanggaran($jenisPelanggaranData);
$pelanggaranData = [
'id_pel' => $this->request->getVar('id_pel'),
'tgl_pel' => $this->request->getVar('tgl_pel'),
'ket' => $this->request->getVar('ket'),
'nis' => $nis,
'id_j_pel' => $this->request->getVar('id_j_pel'), //
Include id_j_pel
];
$this->Objek->savePelanggaran($pelanggaranData);
session()->setFlashdata('pesan', 'Data Telah Berhasil di
Simpan');
return redirect()->to('/Pelanggaran/siswa');
}
public function siswa()
{
$Objek = $this->Objek->findAll();
$data = [
'title' => 'Data Siswa',
'objek' => $Objek
];
echo view('Layout/header', $data);
echo view('Pelanggaran/siswa');
echo view('Layout/footer');
}
public function detail($nis)
{
$siswa = $this->Objek->getSiswa($nis);
$pelanggaran = $this->Objek->lapRelasi($nis);
$data = [
'title' => 'Detail Data Siswa ' . $nis,
'siswa' => $siswa,
'pelanggaran' => $pelanggaran,
];
echo view('Layout/header', $data);
echo view('Pelanggaran/detail', $data);
echo view('Layout/footer');
}
public function tambahdata()
{
session();
$data = [
'title' => 'Formulir Tambah Data Siswa',
'validation' => \Config\Services::validation()
];
echo view('Layout/header', $data);
echo view('Pelanggaran/tambahdata');
echo view('Layout/footer');
}
public function delete($nis)
{
$this->Objek->delete($nis);
session()->setFlashdata('pesan', 'Data Telah Berhasil di
Hapus');
return redirect()->to('/Pelanggaran/isidata');
}
public function editdata($nis)
{
$objek = $this->Objek->getobjek($nis);
$data = [
'title' => 'Edit Data Siswa ' . $objek['nis'],
'objek' => $objek,
];
echo view('Layout/header', $data);
echo view('Pelanggaran/editdata');
echo view('Layout/footer');
}
public function dataedit()
{
$this->Objek->save([
'nis' => $this->request->getVar('nis'),
'nama' => $this->request->getVar('nama'),
'kelas' => $this->request->getVar('kelas'),
'j_k' => $this->request->getVar('j_k'),
'alamat' => $this->request->getVar('alamat'),
]);
session()->setFlashdata('pesan', 'Data Telah Berhasil di
Edit');
return redirect()->to('/Pelanggaran/isidata');
}
public function tampilpel()
{
$ObjekModel = new \App\Models\TpelanggaranModel();
$objek = $ObjekModel->getAllPelanggaran();
$data = [
'title' => 'Tampil Data',
'objek' => $objek,
];
echo view('Layout/header', $data);
echo view('Pelanggaran/tampilpel', $data);
echo view('Layout/footer');
}
}
d. File Config/Routes.php
. <?php
use CodeIgniter\Router\RouteCollection;
/**
* @var RouteCollection $routes
*/
$routes->setAutoRoute(true);
$routes->get('/', 'Pelanggaran::index');
e. File .env
database.default.hostname = localhost
database.default.database = pelanggaran
database.default.username = root
database.default.password =
database.default.DBDriver = MySQLi
database.default.DBPrefix =
database.default.port = 3306