O'Reilly logo

Building a Web Application with PHP and MariaDB: A Reference Guide by Sai Srinivas Sriparasa

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding a course

In this section, we will add the new Courses controller to our controllers' directory. Our Courses controller will extend the Base_Controller class and, upon instantiation, we will load the courses model (we are yet to create the model). The code snippet for the Courses controller will be similar to our Students controller; this is shown in the following code snippet; in the controllers/courses.php file:

<?php
class Courses extends Base_Controller{
  public function __construct(){
    parent::__construct();
    $this->loadModel("courses");
  }

  public function add(){

    if(isset($_POST['submit'])){
      unset($_POST['submit']);
      $this->view->id = $this->model->addCourse($_POST);
    }

    $this->view->render('courses/add');
  }
}

We will be using the add action ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required