Gagal masuk ke detail data

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->detail() #1 C:\xampp\htdocs\sinauMVC\public\index.php(5): App->__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>

avatar Daych
@Daych

1 Kontribusi 0 Poin

Diperbarui 4 tahun yang lalu

1 Jawaban:

ini pakai laravel ya gan?

Harusnya id nya di define jd parameter di route: <pre> Route::get('mahasiswa/{id}', 'Mahasiswa@detail'); </pre>

sumber: https://laravel.com/docs/7.x/controllers

avatar keccikun
@keccikun

368 Kontribusi 197 Poin

Dipost 4 tahun yang lalu

Login untuk ikut Jawaban