8.3. Creating a Newsletter Tool

If you're getting nervous at the thought of creating an e-mail Newsletter tool, don't be. Like any other task in CodeIgniter, you have to think it through in stages and then plan your work accordingly. This reduces the complexity of the task to more manageable parts.

Here are the pieces you'll need to make this work:

  • Some kind of simple form that site visitors can fill out

  • A controller function that accepts the form entry

  • A database table in which to store the information from the form

  • A model that facilitates the use of the form

  • An administrative set of screens that let you manage subscribers and e-mails

As usual, you're going to work from the back forward; that is, you're going to establish the database table and the model first and then work out the controller functions and, eventually, the look and feel of the form itself and where to place it.

8.3.1. Creating the Database Table and Model

The database table for this part of the project should be kept to a minimal number of fields to keep the task of updating it as simple as possible. Although some might argue that you need many different kinds of fields to track subscribers, all you really need is name and email. Your database table will then have three fields: a primary field (id), a name field, and an e-mail field. Nothing more is required to get started.

CREATE TABLE 'subscribers' ( 'id' int(11) NOT NULL auto_increment, 'name' varchar(255) NOT NULL, 'email' varchar(255) NOT NULL, PRIMARY KEY ...

Get Professional CodeIgniter® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.