I use code igniter 4.
I want to make a feature where it displays the extracurricular activities that are currently scheduled for today based on database Column 1 (primary key), column 2 means extracurricular in Indonesia language, column 3 means day in Indonesia language
So when I run, it appears notification error when I add line code p>Hari ini adalah:
But when I erase it, it runs well without that feature Run well without feature day
You can also see my repo github in My github repo
I want to run the line code
p>Hari ini adalah: <?= esc($hari); ?></p> <!-- Menampilkan hari ini -->
Whats does the code mean?
In that code I want to show the extracurricular who has a schedule for today based on SQL database
2
The $hari
variable (or $hariini
in your repo) in that line is used to display the name of today (monday, tuesday, etc in Indonesian). You need to pass a value for this variable from your controller to this view.
Looking at your repo, you already seem to have the code that gets the name of today in EkstraController::index
.
And you also have a model function that gets the activities for a given day, ModelEkstra::getEkstraByDay
.
Using these in your Ekstrakurikulercontroller
should get you the result you want:
<?php
namespace AppControllers;
use AppModelsModelEkstra; // Use the other model
use CodeIgniterController;
class Ekstrakurikulercontroller extends Controller
{
public function index()
{
$namaHari = [
'Sunday' => 'Minggu',
'Monday' => 'Senin',
'Tuesday' => 'Selasa',
'Wednesday' => 'Rabu',
'Thursday' => 'Kamis',
'Friday' => 'Jumat',
'Saturday' => 'Sabtu'
];
$hariInggris = date('l');
$hari = $namaHari[$hariInggris];
$data['hariini'] = $hari; // Set the hariini variable for the view
// Get the activities for today
$model = new ModelEkstra();
$data['ekstrakurikuler'] = $model->getEkstraByDay($hari);
return view('ekstrakurikuler_view', $data);
}
// ...
}
2