Daftar dan Belajar Sekarang!

Gagal masuk ke detail data

foto Daych
1 Kontribusi 0 Coto
1 minggu yang lalu
ketika klik halaman detail data yg diseleksi berdasarkan id, muncul pesan error berikut: <b>Fatal error</b>: Uncaught ArgumentCountError: Too few arguments to function Mahasiswa::detail(), 0 passed in C:\xampp\htdocs\sinauMVC\app\core\App.php on line 35 and exactly 1 expected in C:\xampp\htdocs\sinauMVC\app\controllers\Mahasiswa.php:12 Stack trace: #0 C:\xampp\htdocs\sinauMVC\app\core\App.php(35): Mahasiswa-&gt;detail() #1 C:\xampp\htdocs\sinauMVC\public\index.php(5): App-&gt;__construct() #2 {main} thrown in <b>C:\xampp\htdocs\sinauMVC\app\controllers\Mahasiswa.php</b> on line <b>12</b><br /> controller Mahasiswa.php
<?php 

class Mahasiswa extends Controller{
	public function index(){
		$data['judul'] = 'Daftar Mahasiswa';
		$data['mhs'] = $this->model('Mahasiswa_model')->getAllMahasiswa();
		$this->view('templates/header', $data);
		$this->view('mahasiswa/index', $data);
		$this->view('templates/footer');
	}

	public function detail($id){
		$data['judul'] = 'Detail Mahasiswa';
		$data['mhs'] = $this->model('Mahasiswa_model')->getMahasiswaById($id);
		$this->view('templates/header', $data);
		$this->view('mahasiswa/detail', $data);
		$this->view('templates/footer');
	}
}
model Mahasiswa_model.php
<?php

class Mahasiswa_model{
	
	private $table = 'mahasiswa';
	private $db;

	public function __construct(){
		$this->db = new Database;
	}

	public function getAllMahasiswa(){
		$this->db->query('SELECT * FROM ' . $this->table);
		return $this->db->resultSet();
	}

	public function getMahasiswaById($id){
		$this->db->query('SELECT * FROM ' . $this->table. ' WHERE id=:id');
		$this->db->bind('id', $id);
		return $this->db->single();
	}
}
view detail.php
<div class="container">
	
	<div class="card" style="width: 18rem;">
	  <div class="card-body">
	    <h5 class="card-title"><?= $data['mhs'] ['nama']; ?></h5>
	    <h6 class="card-subtitle mb-2 text-muted"><?= $data['mhs'] ['nrp']; ?></h6>
	    <p class="card-text"><?= $data['mhs'] ['email']; ?></p>
	    <p class="card-text"><?= $data['mhs'] ['jurusan']; ?></p>
	    <a href="<?= BASEURL; ?>mahasiswa" class="card-link">Kembali</a>
	  </div>
	</div>

</div>

Tag: php


Jawaban
foto abyanjksatu
330 Kontribusi 169 Coto
5 hari yang lalu
ini pakai laravel ya gan? Harusnya id nya di define jd parameter di route:
Route::get('mahasiswa/{id}', 'Mahasiswa@detail');
sumber: https://laravel.com/docs/7.x/controllers


Login untuk diksusi di forum sekolah koding