|
3 | 3 | namespace App\Controllers; |
4 | 4 |
|
5 | 5 | use App\Models\DungeonModel; |
6 | | -use App\Models\HeroModel; |
| 6 | +use CodeIgniter\HTTP\ResponseInterface; |
7 | 7 |
|
8 | 8 | class DungeonController extends BaseController |
9 | 9 | { |
10 | 10 | /** |
11 | | - * HeroModel instance. |
| 11 | + * DungeonModel instance. |
12 | 12 | */ |
13 | | - protected $heroes; |
| 13 | + protected DungeonModel $dungeons; |
14 | 14 |
|
15 | 15 | public function __construct() |
16 | 16 | { |
17 | | - // Assign the model to $this->heroes |
| 17 | + // Assign the model to $this->dungeons |
18 | 18 | // so that it's available throughout this class |
19 | 19 | // Use the `model()` helper method to return |
20 | 20 | // a single instance of the model no matter |
21 | 21 | // how many times we call it |
22 | | - $this->heroes = model(DungeonModel::class); |
| 22 | + $this->dungeons = model(DungeonModel::class); |
23 | 23 | } |
24 | 24 |
|
25 | 25 | /** |
26 | | - * View a single hero's details. |
| 26 | + * View a single dungeon's details. |
27 | 27 | * |
28 | | - * The $id parameter is the hero's ID, and is |
| 28 | + * The $id parameter is the dungeon's ID, and is |
29 | 29 | * passed in from the route definition as $1, |
30 | 30 | * since it is the first placeholder in the route. |
| 31 | + * |
| 32 | + * @return ResponseInterface|string |
31 | 33 | */ |
32 | 34 | public function show(int $id) |
33 | 35 | { |
34 | | - $dungeon = $this->heroes->find($id); |
| 36 | + $dungeon = $this->dungeons->find($id); |
35 | 37 |
|
36 | 38 | if ($dungeon === null) { |
37 | 39 | return redirect()->back()->with('error', 'Dungeon not found'); |
38 | 40 | } |
39 | 41 |
|
40 | | - echo view('dungeon', [ |
| 42 | + return view('dungeon', [ |
41 | 43 | 'dungeon' => $dungeon, |
42 | 44 | 'monsters' => $dungeon->monsters(3), |
43 | 45 | ]); |
|
0 commit comments