You are previewing CakePHP 2 Application Cookbook.
O'Reilly logo
CakePHP 2 Application Cookbook

Book Description

Over 60 useful recipes for rapid application development with the CakePHP framework

In Detail

CakePHP is the most popular rapid application development framework for PHP. For over 10 years, this open source project has been the go-to solution for quickly and easily building websites and web applications.

Through a series of over 60 recipes, this book takes you from the basic building blocks of the CakePHP framework to the implementation of routine tasks that will help speed up your development even further. From routing to authentication, the model layer and the events system, as well as views and unit testing, you'll learn how to handle the ins and outs of developments using CakePHP. With fast paced recipes written by a core CakePHP member and official trainer, this book is your piece of the cake!

What You Will Learn

  • Start developing quickly with a lightning-fast introduction to CakePHP
  • Handle HTTP requests and responses, and common tasks such as file uploads and Ajax calls
  • Get up-close and personal with the framework's model layer and events system
  • Discover various routing techniques and a selection of API strategies
  • Fully exploit the command line and CakePHP's shell capabilities
  • Get introduced to the fundamentals of unit testing in the framework
  • See how easily you can maintain and migrate your application's database schema
  • Downloading the example code for this book. 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.

    Table of Contents

    1. CakePHP 2 Application Cookbook
      1. Table of Contents
      2. CakePHP 2 Application Cookbook
      3. Credits
      4. Foreword
      5. About the Authors
      6. About the Reviewer
      7. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      8. 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
      9. 1. Lightning Introduction
        1. Introduction
        2. Listing and viewing records
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        3. Adding and editing records
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Deleting records
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Adding a login
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Including a plugin
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      10. 2. Advanced Routing
        1. Introduction
        2. Adding a prefix
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Handling languages
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Custom route class
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Dispatch filter
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
      11. 3. HTTP Negotiation
        1. Introduction
        2. Parsing extensions
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        3. Processing Ajax requests
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Building a response
          1. Getting ready
          2. How it works...
        5. Uploading a file
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
        6. Using a detector
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        7. Working with cookies
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Cache control
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        9. Error handling
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      12. 4. API Strategies
        1. Introduction
        2. RESTful resources
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        3. Exposing a web service
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Consuming a service
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Authentication API
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. API versioning
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      13. 5. Using Authentication
        1. Introduction
        2. The HTTP authentication
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        3. Custom authorize class
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Facebook authentication
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Custom RBAC
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Working with ACL
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      14. 6. Model Layer
        1. Introduction
        2. Has and belongs to many (HABTM)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        3. Joining through
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Containing models
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Custom finders
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. On-the-fly associations
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        7. Using transactions
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      15. 7. Search and Pagination
        1. Introduction
        2. Pagination
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        3. Basic search and filter
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. See also
        4. The Search plugin
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Advanced search
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      16. 8. Events System
        1. Introduction
        2. Listeners and subscribers
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        3. Event-driven process
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Event stacking
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Managing event priorities
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      17. 9. Creating Shells
        1. Introduction
        2. Console API
          1. How to do it...
          2. How it works...
          3. See also
        3. Import parser
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Running cron shells
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Using the I18n shell
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      18. 10. View Templates
        1. Introduction
        2. Using blocks
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Building an XML view
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Generating a PDF
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Writing some PDF content to a file
          1. See also
        6. Translations
          1. Getting ready
          2. How to do it...
          3. How it works
          4. There's more...
          5. See also
        7. View caching
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        8. The AssetCompress plugin
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      19. 11. Unit Tests
        1. Introduction
        2. Dependency Injection
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        3. Creating a fixture
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Mock objects
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Stub method configuration
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Model unit testing
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
      20. 12. Migrations
        1. Introduction
        2. Schema handling
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        3. Syncing changes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. The Migrations plugin
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Injecting data
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      21. Index