Book Image

Building a Web Application with PHP and MariaDB: A Reference Guide

By : Sai S Sriparasa
Book Image

Building a Web Application with PHP and MariaDB: A Reference Guide

By: Sai S Sriparasa

Overview of this book

Table of Contents (17 chapters)
Building a Web Application with PHP and MariaDB: A Reference Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 to create a new course and add it to our courses table. In our add action, we are passing in the data in the $_POST superglobal over to the addCourse method provided by our courses...