There is only one model in this project—jobs_model.php
— that contains functions that are specific to searching and writing job adverts to the database.
This is our one and only model for this project, so let's create the model and discuss how it functions.
Create the /path/to/codeigniter/application/models/jobs_model.php
file and add the following code to it:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Jobs_model extends CI_Model { function __construct() { parent::__construct(); } function get_jobs($search_string) { if ($search_string == null) { $query = "SELECT * FROM `jobs` WHERE DATE(NOW()) < DATE(`job_sunset_date`) "; } else { $query = "SELECT * FROM `jobs` WHERE `job_title` LIKE '%$search_string%' OR `job_desc` LIKE '%$search_string%' AND DATE(NOW()) < DATE(`job_sunset_date`)"; } $result = $this->db->query($query); if ($result) { return $result; ...