CodeIgniter 1.7 Professional Development

CodeIgniter 1.7 Professional Development
eBook: $23.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 15%!
Print + free eBook + free PacktLib access to the book: $63.98    Print cover: $39.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters


  • Learn expert CodeIgniter techniques and move beyond the realms of the User Guide
  • Create mini-applications that teach you a technique and allow you to easily build extras on top of them
  • Create CodeIgniter Libraries to minimize code bloat and allow for easy transitions across multiple projects
  • Utilize third-party APIs (Twitter oAuth and Facebook Connect) and make use of some less-known helper functions – CodeIgniter's hidden gems
  • A step-by-step, practical guide with examples and screenshots

Book Details

Language : English
Paperback : 300 pages [ 235mm x 191mm ]
Release Date : April 2010
ISBN : 1849510903
ISBN 13 : 9781849510905
Author(s) : Adam Griffiths
Topics and Technologies : All Books, Web Development, Open Source, PHP

Table of Contents

Chapter 1: Getting Started with CodeIgniter
Chapter 2: Learning the Libraries
Chapter 3: Form Validation and Database Interaction
Chapter 4: User Authentication 1
Chapter 5: User Authentication 2
Chapter 6: Application Security
Chapter 7: Building a Large-Scale Application
Chapter 8: Web Services
Chapter 9: Extending CodeIgniter
Chapter 10: Developing and Releasing Code to the Community
  • Chapter 1: Getting Started with CodeIgniter
    • Upgrading from older versions of CodeIgniter
    • Downloading and installing CodeIgniter
      • Getting the CodeIgniter files
    • Introducing Model View Controller (MVC)
    • Controllers: The business logic
      • Defining a default Controller
      • Remapping function calls
    • Models: Data abstraction layer
      • Loading a Model
      • Connecting to your database automatically
    • Views: Your template files
      • Loading a view
      • Loading multiple views
      • Adding dynamic data
      • Creating loops
      • Returning views as data
    • Autoloading resources
    • Formatting your code—PHP Style Guide
      • PHP closing tag
        • Incorrect
        • Correct
      • Class and method naming
        • Incorrect
        • Correct
        • Incorrect
        • Correct
      • Variable names
        • Incorrect
        • Correct
      • Commenting
        • Poor
        • Good
      • Use of TRUE, FALSE, and NULL
        • Incorrect
        • Correct
      • Short opening tags
        • Incorrect
        • Correct
      • One statement per line
        • Incorrect
        • Correct
    • CodeIgniter URLs
      • Removing the index.php file
      • Adding a URL Suffix
    • CodeIgniter specific files
      • Helpers
        • Loading a helper
        • Using a helper
        • "Extending" Helpers
      • Plugins
        • Loading a plugin
        • Loading multiple plugins
        • Using a plugin
      • Libraries
        • Creating your own libraries
        • Extending core libraries
        • Replacing core libraries
    • Summary
  • Chapter 2: Learning the Libraries
    • What is a library?
    • What do libraries do?
    • Benchmarking Class
      • Setting a benchmark
      • Setting multiple benchmarks
      • Profiling your benchmarks
        • Making use of the Profiler Class
      • Display total execution time
      • Display memory consumption
    • Input and Security Class
      • XSS filtering
        • Filtering a single item
        • Automatic filtering
        • Filtering images
        • Retrieving POST data
        • Retrieving GET data
        • Retrieving GET and POST data
        • Retrieving COOKIE data
        • Retrieving SERVER data
        • IP Addresses
        • Retrieving a user agent
    • Email Class
      • Send an e-mail
      • Build a contact form
        • Our contact form
        • Checking if the form has been submitted
        • Checking the values of the form
        • Validate the e-mail
        • Using the XSS filter
        • Send the e-mail
      • Batch e-mail processing
    • File Uploading Class
      • Create the Upload Views
      • Create the Upload Controller
        • Our initial controller
        • Specify the allowed file types and maximum file size
        • Uploading the file
    • Image Manipulation Library
      • Initializing the library
      • Creating a thumbnail
      • Cropping an image
      • Rotating an image
      • Clearing values in loops
    • Pagination Class
      • Example
      • Customizing the pagination
      • Customize the "First" link
      • Customize the "Last" link
      • Customize the "Next" link
      • Customize the "Previous" link
      • Customize the "Current Page" link
      • Customize the "Digit" link
    • Session Class
      • Initializing the Session Class
        • Autoload the Session Class
        • Manually load the Session Class
      • How do CodeIgniter sessions work?
      • What is stored in a session?
      • Adding session data
      • Retrieving session data
      • Removing session data
        • Removing a single session item
        • Removing multiple session items
        • Destroying a session
      • Flash data
        • Add flashdata
        • Read flashdata
        • Keep flashdata
      • Using a session database
    • Unit testing a class
      • Initializing the class
      • Running tests
      • Generating reports
      • Strict mode
      • Enabling or disabling unit testing
      • Create a template
    • Summary
  • Chapter 3: Form Validation and Database Interaction
    • Why should I validate my forms?
    • Using the Form Validation Library
      • The form validation process
        • The user's process
        • The development process
      • Contact form
        • Loading the assets
        • Setting the rules
        • Check the validation process
        • Sending the email
        • Final controller code
      • Changes to the form view
        • Re-populating field values
        • Showing individual errors
        • Final form view
        • Changing the error delimiters
    • Saving sets of validation rules to a config file
      • Creating sets of rules
      • Calling a specific set of rules
      • Associating a rule group with a controller
    • Using callbacks
      • Include the callback in the rules
      • Creating the callback
        • Create the function
        • Load the database library
        • Performing the database query
        • Adding a condition
        • Show a success page
    • Database interaction
      • Loading the library
    • Performing simple queries
    • Returning values
      • Returning a result object
      • Returning a result array
      • Returning a row object
      • Returning a row array
    • Result helper functions
      • Number of rows returned
      • Number of fields returned
      • Free result
    • Active Record
      • Selecting data
        • $this->db->get();
        • $this->db->get_where();
        • $this->db->select();
        • $this->db->from();
        • $this->db->join();
        • $this->db->where();
        • $this->db->like();
        • $this->db->group_by();
        • $this->db->order_by();
        • $this->db->limit();
      • Inserting data
        • $this->db->insert();
        • $this->db->set();
      • Updating data
        • $this->db->update();
      • Deleting data
        • $this->db->delete();
        • $this->db->empty_table();
        • $this->db->truncate();
    • Active Record caching
      • $this->db->start_cache();
      • $this->db->stop_cache();
      • $this->db->flush_cache();
    • Method chaining
    • Manipulating databases with Database Forge
      • Loading the Forge class
      • Creating a database
      • Dropping a database
      • Adding fields
      • Creating a table
      • Dropping a table
      • Renaming a table
      • Modifying a table
        • $this->dbforge->add_column();
        • $this->dbforge->drop_column();
        • $this->dbforge->modify_column();
    • Summary
  • Chapter 4: User Authentication 1
    • Defining our goals
      • Our goals
    • Creating and connecting to the database
    • Front end code
      • Index function
        • Details view
      • Dashboard function
        • Dashboard view
      • Login function
        • Form validation
        • Running the validation
        • Full login code
        • Login view
        • Success view
      • Register function
        • Form validation
        • Running the validation
        • Full register code
        • Full controller code
        • Register view
        • Error view
      • Logout function
        • Logout view
    • Model code
      • Model constructor
      • Create function
      • Login function
      • Logged in check function
      • Full model code
    • Addressing some issues
    • The Authentication Library
    • Summary
  • Chapter 5: User Authentication 2
    • Using Twitter oAuth
      • How oAuth works
      • Registering a Twitter application
      • Downloading the oAuth library
        • Library base class
        • Controller base class
        • Library constructor
        • Requesting user tokens
        • HTTP function
        • Parse function
        • Controller index function
        • get_authorize_URL function
        • Main view file
        • Change your callback URL
        • Creating the access function
        • The view file
        • Getting access tokens
        • Logging out
        • Debug function
        • Final library code
        • Final controller code
    • Using Facebook Connect
      • Registering a Facebook application
      • Download the Client library
      • Our CodeIgniter Wrapper
        • Base class
        • Class constructor
        • _session();
        • Final library code
      • The Controller
      • The View file
    • Summary
  • Chapter 6: Application Security
    • CodeIgniter's defenses
      • URI security
        • Why does CodeIgniter use URIs?
        • Why does CodeIgniter restrict URI characters?
      • Global data
      • Best practices
        • Filtering data
        • Validation
        • Escaping data
    • Strong password policies
      • Example form Validation library rules
    • Storing passwords securely
      • Storing hashes
        • Hashing a password using sha1
      • Static salting
        • Simple salts
        • Complex salts
      • Dynamic salting
        • Simple dynamic salts
        • Complex dynamic salts
      • Encrypting passwords
        • Setting an encryption key
        • Message length
        • Loading the class
        • Encoding passwords
        • Decoding passwords
        • Set mcrypt cipher
    • Database security
      • Escape queries
        • The $this->db->escape() function
        • The $this->db->escape_str() function
        • The $this->db->escape_like_str() function
        • Query bindings
      • Limiting account access
    • Cross-site scripting (XSS)
    • Changing the default file structure
    • Staying up-to-date
    • Summary
  • Chapter 7: Building a Large-Scale Application
    • Running benchmarks
      • Why run benchmarks?
      • Where should I use benchmarks?
      • Types of bottlenecks
        • Database
        • Code
        • API
        • Bandwidth
        • Static
    • Caching
      • How does it work?
      • How long should I cache pages for?
      • Using caching
    • Optimize SQL queries
      • Query caching
        • To cache or not to cache?
        • How query caching works
        • Managing cache files
        • Using query caching
        • Deleting cache files
        • Deleting all cache files
      • Limit results
        • LIMIT clause
        • Only select what you need
    • Avoid disk activity
      • Memcache example
      • Memcache CodeIgniter library
        • Constructor
        • Data functions
        • Maintenance functions
        • Full library code
        • Using the library
    • Run multiple application instances
      • Advantages
      • Disadvantages
    • Summary
  • Chapter 8: Web Services
    • What is a web service?
    • Types of web service
      • Remote procedure call
      • Representational State Transfer
    • RESTful web service
      • Defining the resource
      • How it will work
      • Creating our files
      • Setting up the database
      • REST library
        • Base class
        • Performing a GET request
        • Performing a PUT request
        • Performing a POST request
        • Performing a DELETE request
        • Response function
        • The format XML function
        • The format JSON function
        • Final library code
      • Rest Controller
        • Base class
        • The _remap() function
      • Server Controller
        • Base class
        • The post_get() function
        • The post_put() function
        • The post_delete() function
        • The post_post() function
        • Final server controller code
      • Post Model
        • Base class
        • The get_post() function
        • The update_post() function
        • The create_post() function
        • The delete_post() function
        • Final post model code
    • Create a new post
    • Update a post
    • Delete a post
    • Get a blog post
    • Summary
  • Chapter 9: Extending CodeIgniter
    • Hooks
      • Hook points
        • pre_system
        • pre_controller
        • post_controller_constructor
        • post_controller
        • display_override
        • cache_override
        • scaffolding_override
        • post_system
      • Our hook
        • Enable hooks
        • Define a hook
        • Our hook
    • Extended controllers
      • Admin controller
    • Extended libraries
      • The library
        • Base class
        • userdata()
        • set_userdata()
        • unset_userdata()
        • Full library code
    • Custom libraries
      • The features
      • The library
      • The controller
    • Helpers
    • CodeIgniter's hidden gems
      • doctype()
      • Array helper
        • element()
        • random_element()
      • Inflector helper
        • singular()
        • plural()
        • camelize()
        • underscore()
        • humanize()
      • highlight_code()
      • directory_map()
    • Summary
  • Chapter 10: Developing and Releasing Code to the Community
    • Find a need in the community (or fill your own need)
    • Search for existing solutions
      • Use the solutions
      • Reinvent the wheel
      • List the problems of these solutions
    • Create a plan
      • List the features
      • Prioritize the features
    • Writing the library
      • Review your code
        • Comments
      • Fix the problems
    • Write a user guide
      • Explain the function
      • Show the user how to use the function
      • Let the user know of any shortcomings
      • Use the style sheet given in the CodeIgniter User Guide
    • Release options
      • Forum post
      • Post on your website
      • GitHub
    • Handling database tables
      • Include a .sql file
      • Include an install file
    • Supporting the code
      • Update regularly
      • Listen to the users
      • Accept contributions
      • Communicate regularly
      • Don't give a release date
      • Keep testing
      • Archive old versions
      • Use the wiki
    • Summary

Adam Griffiths

Adam Griffiths is a student and freelance CodeIgniter Developer based in the United Kingdom. He has five years web development experience, the last two being largely influenced by CodeIgniter. He has worked on many websites, both large and small, from small blogs to large multi-national companies. He is well versed in development techniques and how to squeeze that little bit more from an application. He has also made a number of contributions to the CodeIgniter Community, most notably The Authentication Library, a very simple-to-use but full-featured Authentication Library for CodeIgniter.

When CodeIgniter and PHP aren't spiralling around his head, Adam enjoys practising card and mentalist tricks, mainly sleight of hand and card handling. He has performed at local and formal functions for hundreds of people. He is also a guitar player and enjoys playing acoustically at pubs and small gigs. Moving back towards computing, he has a deep interest in Cryptography. He loves finding patterns in data and loves using pen and paper to decipher any cipher text he may find around the web.

Code Downloads

Download the code and support files for this book.

Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


- 2 submitted: last submission 09 Jun 2014

Errata type: Code

Chapter 4, Page No. 100, in "Login Function" section
It should be

Errata type: Typo | Page number: 21

In the Commenting section, it is given as * @link

It should be * @link

Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Frequently bought together

CodeIgniter 1.7 Professional Development +    Ext JS 3.0 Cookbook =
50% Off
the second eBook
Price for both: $37.50

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

What you will learn from this book


  • Learn the Model-View-Controller design pattern to structure your code
  • Create more readable and maintainable queries using the Active Record implementation
  • Create and maintain database tables using the Database Forge class
  • Authenticate users using Twitter oAuth and Facebook Connect
  • Create your own Authentication Library for more control over your user accounts
  • Secure your application using CodeIgniter's built-in functionality and some quick tips to help further
  • Build a RESTful Web Service, opening up your application to third-party developers
  • Create extended Controllers, grouping functionality into multiple Controllers helping to keep repeated code to a minimum
  • Learn techniques used by professionals to scale CodeIgniter over multiple servers
  • Learn top tips for releasing code to the community and giving support to the developers using your code

In Detail

CodeIgniter is an open source PHP framework with a small footprint and exceptional performance. It gives you a rich set of libraries for common tasks, with a simple interface to access them. There are several unexplored aspects of CodeIgniter that can help developers build applications more easily and quickly. In this book, you will learn the intricacies of the framework and explore some of its hidden gems.

If you want to get the most out of CodeIgniter, this book is for you. It teaches you what you need to know to use CodeIgniter on a daily basis. You will create mini-applications that teach a specific technique and let you build on top of the base.

This book will take you through developing applications with CodeIgniter. You will learn how to make your CodeIgniter application more secure than a default installation, how to build large-scale applications and web services, how to release code to the community, and much more. You will be able to authenticate users, validate forms, and also build libraries to complete different tasks and functions.

The book starts off introducing the framework and how to install it on your web server or a local machine. You are introduced to the Model-View-Controller design pattern and how it will affect your development. Some important parts of the CodeIgniter Style Guide are included to keep CodeIgniter development as standardized as possible; this helps greatly when working as part of a team or taking on an old CodeIgniter project. You will quickly move on to how CodeIgniter URLs work and learn about CodeIgniter-specific files such as helpers and plugins. By the time you finish this book, you will be able to create a CodeIgniter application of any size with confidence, ease, and speed.

This guide will enable you to become well-versed with CodeIgniter through practical applications using the tools and techniques used by many seasoned CodeIgniter developers.


This book is a practical guide that takes you through a number of techniques. Each chapter builds upon knowledge from the previous chapter. Step-by-step instructions with examples and illustrative screenshots ensure that you gain a firm grasp of the topic being explained.

Who this book is for

This book is written for advanced PHP developers with a good working knowledge of Object Oriented Programming techniques who are comfortable with developing applications and wish to use CodeIgniter to make their development easier, quicker, and more fun. Basic knowledge of CodeIgniter will be helpful. This book will suit developers who fall into three categories:

  • Professional Developers – employees of a software house or organization with in-house software development
  • Freelance Developers – solo developers working in the industry on their own
  • Just-for-fun Developers – people working with PHP building web applications is their spare time for fun

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software