You are previewing CakePHP 1.3 Application Development Cookbook.
O'Reilly logo
CakePHP 1.3 Application Development Cookbook

Book Description

Over 70 great recipes for developing, maintaining, and deploying web applications

  • Create elegant and scalable web applications using CakePHP

  • Leverage your find operations with virtual fields, ad-hoc queries, and custom find types

  • Add full internationalization support to your application, including translation of database records

  • Part of Packt's Cookbook series: Each recipe is a carefully organized sequence of instructions to complete the task as efficiently as possible

  • In Detail

    CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying web applications. While the framework has a lot of documentation and reference guides available for beginners, developing more sophisticated and scalable applications require a deeper knowledge of CakePHP features, a challenge that proves difficult even for well established developers.

    The recipes in this cookbook will give you instant results and help you to develop web applications, leveraging the CakePHP features that allow you to build robust and complex applications. Following the recipes in this book you will be able to understand and use these features in no time.

    We start with setting up authentication on a CakePHP application. One of the most important aspects of a CakePHP application: the relationship between models, also known as model bindings. Model binding is an integral part of any application's logic and we can manipulate it to get the data we need and when we need. We will go through a series of recipes that will show us how to change the way bindings are fetched, what bindings and what information from a binding is returned, how to create new bindings, and how to build hierarchical data structures. We also define our custom find types that will extend the three basic ones, allowing our code to be even more readable and also create our own find type, with pagination support. This book also has recipes that cover two aspects of CakePHP models that are fundamental to most applications: validation, and behaviors.

    A cookbook for CakePHP developers on how to leverage one of the most popular PHP frameworks, including recipes for working with AJAX, datasources, GEO location, routing, performance optimization, and more.

    Table of Contents

    1. CakePHP 1.3 Application Development Cookbook
      1. CakePHP 1.3 Application Development Cookbook
      2. Credits
      3. About the Author
      4. About the Reviewers
      5. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      6. 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. Errata
          2. Piracy
          3. Questions
      7. 1. Authentication
        1. Introduction
        2. Setting up a basic authentication system
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Hashing a password confirmation field
          4. See also
        3. Using and configuring the Auth component
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Changing the default user model
          4. There's more...
          5. See also
        4. Allowing logins with username or e-mail
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Saving the user details after login
          1. Getting ready
          2. How to do it...
            1. How it works...
            2. See also
        6. Getting the current user's information
          1. Getting ready
          2. How to do it...
            1. How it works...
            2. See also
        7. Using prefixes for role-based access control
          1. Getting ready
          2. How to do it...
            1. How it works...
            2. See also
        8. Setting up Access Control Layer-based authentication
          1. Getting ready
            1. How to do it...
            2. How it works...
            3. There's more...
            4. See also
        9. Integrating with OpenID
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      8. 2. Model Bindings
        1. Introduction
        2. Adding Containable to all models
          1. How to do it...
          2. How it works...
          3. See also
        3. Limiting the bindings returned in a find
          1. Getting ready
            1. How to do it...
            2. How it works...
              1. Format of the contain find parameter
              2. Reset of binding changes
            3. See also
        4. Modifying binding parameters for a find
          1. Getting ready
            1. How to do it...
            2. How it works...
            3. See also
        5. Modifying binding conditions for a find
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Changing the JOIN type of one-to-one associations
          1. Getting ready
          2. How to do it...
            1. How it works...
        7. Defining multiple associations to the same model
          1. Getting ready
            1. How to do it...
            2. There's more...
        8. Adding bindings on the fly
          1. Getting ready
          2. How to do it...
          3. How it works...
      9. 3. Pushing the Search
        1. Introduction
        2. Performing GROUP and COUNT queries
          1. Getting ready
            1. How to do it...
            2. How it works...
            3. See also
        3. Using virtual fields
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Building queries with ad-hoc JOINs
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Searching for all items that match search terms
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Implementing a custom find type
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        7. Paginating a custom find type
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        8. Implementing AJAX based pagination
          1. Getting ready
          2. How to do it...
            1. How it works...
      10. 4. Validation and Behaviors
        1. Introduction
        2. Adding multiple validation rules
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Creating a custom validation rule
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Using callbacks in behaviors
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Using behaviors to add new fields for saving
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Using the Sluggable behavior
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Geocoding addresses with the Geocodable behavior
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
      11. 5. Datasources
        1. Introduction
        2. Improving the SQL datasource query log
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Parsing CSV files with a datasource
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Dynamic loading of CSV files
        4. Consuming RSS feeds with a datasource
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Changing connection settings at runtime
        5. Building a Twitter datasource
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Adding transaction and locking support to the MySQL datasource
          1. Getting ready
          2. How to do it...
          3. How it works...
      12. 6. Routing Magic
        1. Introduction
        2. Using named and GET parameters
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Using routes with prefixes
          1. Getting ready
          2. How to do it...
            1. How it works...
            2. See also
        4. Working with route elements
          1. Getting ready
          2. How to do it...
            1. How it works...
            2. There's more...
              1. Using reverse routing
            3. See also
        5. Adding catch-all routes for profile pages
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Adding validation for catch-all routes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        7. Creating custom Route classes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      13. 7. Creating and Consuming Web Services
        1. Introduction
        2. Creating an RSS feed
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Adding view caching to an RSS feed
          4. See also
        3. Consuming a JSON service
          1. How to do it...
          2. How it works...
          3. See also
        4. Building REST services with JSON
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Adding authentication to REST services
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Implementing token-based authorization for API access
          1. Getting ready
          2. How to do it...
          3. How it works...
      14. 8. Working with Shells
        1. Introduction
        2. Building and running a shell
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Using the Auth component for hashing passwords
          4. See also
        3. Parsing command line parameters
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Creating reusable shell tasks
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Sending e-mails from shells
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Non-interactive tasks with the robot plugin
          1. Getting ready
          2. How to do it...
          3. How it works...
      15. 9. Internationalizing Applications
        1. Introduction
        2. Internationalizing controller and view texts
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Domains and categories
          4. See also
        3. Internationalizing model validation messages
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Translating strings with dynamic content
          1. Getting ready
          2. How to do it...
            1. How it works...
              1. Reordering and reusing interpolation arguments
            2. See also
          3. Extracting and translating text
            1. Getting ready
            2. How to do it...
            3. How it works...
          4. Translating database records with the Translate behavior
            1. Getting ready
            2. How to do it...
            3. How it works...
              1. Using separate translation tables
            4. See also
        5. Setting and remembering the language
          1. Getting ready
          2. How to do it...
          3. How it works...
      16. 10. Testing
        1. Introduction
        2. Setting up the test framework
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Creating fixtures and testing model methods
          1. Getting ready
          2. How to do it...
            1. How it works...
            2. There's more...
              1. Extending models to avoid testing unneeded bindings
              2. Analyzing code coverage
            3. See also
        4. Testing controller actions and their views
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Using mocks to test controllers
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        6. Running tests from the command line
          1. Getting ready
          2. How to do it...
          3. How it works...
      17. 11. Utility Classes and Tools
        1. Introduction
        2. Working with the Set class
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        3. Manipulating strings with the String class
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Sending an e-mail
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Detecting file types with MagicDb
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Throwing and handling exceptions
          1. Getting ready
          2. How to do it...
          3. How it works...