Book Image

CodeIgniter Web Application Blueprints

Book Image

CodeIgniter Web Application Blueprints

Overview of this book

Table of Contents (16 chapters)
CodeIgniter Web Application Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating the models


We're going to create three models for this application; these are as follows:

  • discussions_model.php: This helps in managing interactions with the discussions table

  • comments_model.php: This helps in managing interactions with the comments table

  • admin_model.php: This helps in managing interactions with the users table

Creating the model file – models/discussions_model.php

The discussions_model.php model file has three functions; these are fetch_discussions(), fetch_discussion(), and flag(). The fetch_discussions() function fetches many discussions, the fetch_discussion() function fetches a single discussion, and the flag() function sets a discussion as one that requires moderation by an admin.

The steps to create this model file are as follows:

Create the /path/to/codeigniter/application.models/discussion_model.php file and add the following code to it:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Discussions_model extends CI_Model {...