Book Image

CodeIgniter 2 Cookbook

By : Robert Foster
Book Image

CodeIgniter 2 Cookbook

By: Robert Foster

Overview of this book

As a developer, there are going to be times when you'll need a quick and easy solution to a coding problem. CodeIgniter is a powerful open source PHP framework which allows you to build simple yet powerful full-feature web applications. CodeIgniter 2 Cookbook will give you quick access to practical recipes and useful code snippets which you can add directly into your CodeIgniter application to get the job done. It contains over 80 ready-to-use recipes that you can quickly refer to within your CodeIgniter application or project.This book is your complete guide to creating fully functioning PHP web applications, full of easy-to-follow recipes that will aid you in any aspect of developing with CodeIgniter. CodeIgniter 2 Cookbook takes you from the basics of CodeIgniter, through e-commerce features for your applications, and ends by helping you ensure that your environment is secure for your users and SEO friendly to draw in customers. Starting with installation and setup, CodeIgniter 2 Cookbook provides quick solutions to programming problems that you can directly include in your own projects. You will be moving through databases, EU Cookie Law, caching, and everything else in-between with useful, ready-to-go recipes. You will look at image manipulation using the Image Manipulation library, user management (building a simple CRUD interface), switching languages on the fly according to the user preference, caching content to reduce server load, and much more.
Table of Contents (18 chapters)
CodeIgniter 2 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

CodeIgniter 2 Cookbook offers many easy-to-use, easy-to-integrate, and easy-to-adapt recipes using HTTPS, image manipulation, cookie acceptance, form validation, and so on. It is a great resource for 2 AM problems.

What this book covers

Chapter 1, CodeIgniter Basics, takes you through CodeIgniter's download and installation, basic configuration, and so on.

Chapter 2, User Management, focuses on building a basic CRUD interface for managing users.

Chapter 3, Creating E-commerce Features, explores the use of the CodeIgniter Cart class to create a simple storefront, allowing a customer to add items to the cart and checkout.

Chapter 4, Email, HTML Table, and Text Libraries, focuses on sending e-mails using the CodeIgniter Email library, creating interactive tables, and using a few handy HTML functions.

Chapter 5, Managing Data In and Out, deals with form validation, writing files to disk, confirming cookie acceptance from the user, and so on.

Chapter 6, Working with Databases, covers the usage of basic Active Record functions, exporting data from a database query binding, and most of what you might need to work with databases.

Chapter 7, Creating a Secure User Environment, covers escaping user input, switching to and from HTTPS in CodeIgniter, and so on.

Chapter 8, Calendaring, Right Place, and Right Time, deals with creating an interactive calendar that you can add appointments to using fuzzy dates and calculating a person's date of birth (for age verification).

Chapter 9, Extending the Core, focuses on using the language class and switching languages on the go, creating hooks, uploading files with FTP, and extending your controllers with MY_Controller.

Chapter 10, Working with Images, deals with using the CodeIgniter image manipulation library to crop, rotate, and add watermarks to images and adding CAPTCHA validation to forms.

Chapter 11, SEO, Caching, and Logging, deals with caching data from a database, using the CodeIgniter routing methods to alter and amend how URLs are displayed in a browser's address bar, and logging errors and other activities throughout your application.

What you need for this book

You will require the following software:

  • An *AMP environment (LAMP, MAMP, WAMP, and so on)

  • A copy of the CodeIgniter framework

Who this book is for

CodeIgniter is an easy-to-pick-up framework written in PHP; so, familiarity with PHP and CodeIgniter is advantageous. But, having no experience with CodeIgniter shouldn't be a road block to read the book either. The best thing to do (if you're unsure) is to buy it and just jump in. Having said that, if you are familiar with CodeIgniter, this book can provide immediate sold snippets and recipes you can use for all sorts of day-to-day, CodeIgniter-related tasks.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: " The public function index() function redirects us to the function public function send_mail()."

A block of code is set as follows:

$this->email->from('[email protected]', 'Your Name');
$this->email->to('[email protected]');

$this->email->subject('This is a text email');
$this->email->message('And this is some content for the text email.');

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

function __construct() {
    parent::__construct();
    $this->load->helper('url');
    $this->load->library('email');
}

Any command-line input or output is written as follows:

C:\path\to\CodeIgniter\file.htaccess" .htaccess

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "The user clicks on View Cart to view the products they wish to order".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.