Listing all courses
In this section, we will focus on listing all the courses in the database on the page. We will begin by adding the get
action to our Courses
controller that will use the getCourses
method provided by the courses
model. Once the data is retrieved from the getCourses
method, the data is forwarded to the get.php
view from our get
action in the controllers/courses.php
file:
public function get($id=null){ $this->view->course_data = $this->model->getCourses(); $this->view->render('courses/get'); }
The code of the models/courses_model.php
file is as follows:
public function getCourses(){ return $this->db->query("SELECT course_id, name, description FROM courses;")->fetchAll(PDO::FETCH_ASSOC); }
The code of the views/courses/get.php
file is as follows:
<div id="getCourses"> <table> <tr> <th>Course Id</th> <th>Course Name</th> <th>Description</th> </tr> <?php...