You are previewing CodeIgniter 2 Cookbook.
O'Reilly logo
CodeIgniter 2 Cookbook

Book Description

As a PHP developer, you may have wondered how much difference the Codeigniter framework might make when creating web applications. Now you can find out with a host of customizable recipes ready to insert into your own work.

  • Customizable code that can be used in your own applications right away

  • Recipes that will help you solve your Codeigniter issues efficiently and effectively

  • Each recipe comes with a full code example, and where necessary, the Model and View files are included too

  • In Detail

    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

    1. CodeIgniter 2 Cookbook
      1. Table of Contents
      2. CodeIgniter 2 Cookbook
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. CodeIgniter Basics
        1. Introduction
        2. Downloading and installing CodeIgniter
          1. How to do it...
        3. Basic configuration options
          1. How to do it...
            1. How it works...
          2. Managing CodeIgniter on different environments
            1. How to do it...
            2. How it works...
          3. Managing database settings on different environments
            1. How to do it...
            2. How it works...
              1. Common values
              2. Other values
          4. Securing the system files
            1. How to do it...
            2. How it works...
          5. Removing index.php from the address bar using .htaccess
            1. How to do it...
            2. How it works...
          6. Installing and using Sparks
            1. How to do it...
            2. How it works...
      9. 2. User Management
        1. Introduction
          1. Database schema
        2. Viewing users
          1. How to do it...
          2. How it works...
        3. Creating users
          1. How to do it...
          2. How it works...
        4. Editing users
          1. How to do it...
          2. How it works...
        5. Deleting users
          1. How to do it…
          2. How it works...
        6. Generating passwords with CodeIgniter
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Generating passwords with CodeIgniter – the bare bones
          1. How to do it...
            1. Generating a hash
            2. Comparing hashed values
          2. How it works...
        8. Forgot password? – resetting passwords with CodeIgniter
          1. Getting ready
          2. How to do it...
          3. How it works...
      10. 3. Creating E-commerce Features
        1. Introduction
        2. Amending configuration settings to run sessions in a database
          1. Getting ready
          2. How to do it...
          3. How it works…
            1. Categories table
            2. Products table
        3. Creating a basic cart
          1. How to do it...
          2. How it works...
            1. User browses the catalogue
            2. User adds an item to the cart
            3. User updates or removes items in the cart
        4. Adding and searching by product categories
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Saving the cart to the database
          1. How to do it...
          2. How it works...
      11. 4. Email, HTML Table, and Text Libraries
        1. Introduction
        2. Sending plain e-mails with CodeIgniter Email
          1. How to do it...
          2. How it works...
        3. Sending HTML e-mails with CodeIgniter Email
          1. How to do it...
          2. How it works...
        4. Sending attachments with CodeIgniter Email
          1. How to do it...
          2. How it works...
        5. Sending bulk e-mails with CodeIgniter Email
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Using an HTML table with DataTable
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Using an HTML table with DataTable and a database
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Using word_limiter() for table output
          1. Getting ready
          2. How to do it...
          3. How it works...
        9. Using word_censor() for cleaning input
          1. Getting ready
          2. How to do it...
          3. How it works...
      12. 5. Managing Data In and Out
        1. Introduction
        2. Sending different data to multiple views
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Validating user input
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Preparing user input
          1. How to do it...
        5. Sticky form elements in CodeIgniter
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Displaying errors next to form items
          1. How to do it...
          2. How it works...
        7. Reading files from the filesystem
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Writing files to the filesystem
          1. How to do it...
          2. How it works...
        9. Creating and downloading ZIP files
          1. How to do it...
          2. How it works...
        10. Uploading files with CodeIgniter
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        11. Creating and using validation callbacks
          1. How to do it...
          2. How it works...
        12. Using the language class
          1. Getting ready
          2. How to do it...
          3. How it works...
        13. Confirming cookie acceptance from the user
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There’s more...
      13. 6. Working with Databases
        1. Introduction
        2. Configuring CodeIgniter for databases
          1. How to do it...
          2. How it works...
        3. Connecting to multiple databases
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Active Record – create (insert)
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. The public function create()
            2. The public function create_batch()
        5. Active Record – read (select)
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Active Record – update
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. ActiveRecord – delete
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Looping through the database results
          1. Getting ready
          2. How to do it...
          3. How it works...
        9. Counting the number of returned results with num_rows()
          1. How to do it...
          2. How it works...
        10. Counting the number of returned results with count_all_results()
          1. How to do it...
        11. Query binding
          1. Getting ready
          2. How to do it...
          3. How it works
        12. Finding the last insert id
          1. How to do it...
          2. How it works...
        13. Finding the number of affected rows
          1. How to do it...
          2. How it works...
        14. Finding the last database query
          1. How to do it...
          2. How it works...
        15. Using CodeIgniter database migrations
          1. Getting ready
          2. How to do it...
        16. Moving to the current version with current()
          1. Getting ready
          2. How to do it...
          3. How it works...
        17. Rolling back/stepping forward with version()
          1. Getting ready
          2. How to do it...
          3. How it works...
        18. Generating an XML from a database result
          1. Getting ready
          2. How to do it...
          3. How it works...
        19. Generating a CSV from a database result
          1. Getting ready
          2. How to do it...
            1. Forcing download
          3. How it works...
            1. Saving to file
          4. How it works...
          5. There's more...
      14. 7. Creating a Secure User Environment
        1. Introduction
        2. Escaping user input
          1. Getting ready
          2. How to do it...
            1. Globally
            2. Individually
          3. How it works...
        3. Preventing cross-site request forgery
          1. How to do it...
          2. How it works...
        4. Escaping data – for a database
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        5. Using HTTPS with CodeIgniter
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Setting up HTTPS on localhost
      15. 8. Calendaring, Right Place, and Right Time
        1. Introduction
        2. Building a CodeIgniter Calendar helper with database results
          1. Getting ready
          2. How to do it…
          3. How it works…
        3. Building an appointment manager with Calendar Library
          1. Getting ready
          2. How to do it…
          3. How it works…
            1. The public function create()
            2. The public function delete()
        4. Creating a helper to work with a person's date of birth
          1. How to do it…
          2. How it works…
        5. Working with fuzzy dates in CodeIgniter
          1. How to do it…
          2. How it works…
      16. 9. Extending the Core
        1. Introduction
        2. Using CodeIgniter Sparks
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Creating PDFs with the DOMPDF Spark
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Creating Hooks in CodeIgniter
          1. Getting ready
          2. How to do it...
        5. Clearing dead sessions from the database
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Extending your controllers
          1. How to do it...
          2. How it works...
        7. Uploading a file with FTP
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Creating libraries and giving them access to CodeIgniter resources
          1. Getting ready
          2. How to do it...
          3. How it works...
        9. Making your own configuration files and using the settings
          1. How to do it...
          2. How it works...
        10. Using the language class – switching language on the go
          1. Getting ready
          2. How to do it...
          3. How it works...
      17. 10. Working with Images
        1. Introduction
        2. Installing ImageMagick on MAC with Cactuslab
          1. How to do it...
          2. How it works...
        3. Uploading images with CodeIgniter
          1. How to do it...
          2. How it works...
        4. Generating thumbnails – resizing
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Rotating images
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Cropping images
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Potential errors
        7. Adding watermarks with text
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Adding watermarks with image overlays
          1. Getting ready
          2. How to do it...
          3. How it works...
        9. Submitting a form with CodeIgniter CAPTCHA
          1. Getting ready
          2. How to do it...
          3. How it works...
      18. 11. SEO, Caching, and Logging
        1. Introduction
        2. Using SEO-friendly URLs in CodeIgniter
          1. How to do it...
          2. How it works...
        3. Using CodeIgniter caching
          1. How to do it...
          2. How it works...
            1. Problems you may encounter
        4. Logging errors with CodeIgniter
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Logging style
        5. Benchmarking your application
          1. Getting ready
          2. How to do it...
          3. How it works...
      19. Index