CakePHP Application Development Step-by-step introduction to rapid web development using the open-source MVC CakePHP framework Ahsanul Bari Anupom Syam PUBLISHING BIRMINGHAM - MUMBAI
Preface 1 What This Book Covers 1 Who is This Book for 2 Conventions 2 Reader Feedback 3 Customer Support 3 Downloading the Example Code for the Book 3 Errata 4 Questions 4 Introduction to CakePHP 5 What is CakePHP? 5 A PHP Framework 6 Common Design Patterns 6 Rapid Web Development 6 Works with PHP4 and PHP5 7 CakePHP is Free and Open Source 7 Improved Code Structure 7 Understanding the MVC Pattern 8 Models 8 Controllers 8 Views 9 How It Works 9 Faster Development 10 Less Configuration, More Convention 10 Auto Code Generation 10 Quick Access to Related Data 10 Built-in Commonly Used Functionalities 11 Versions of CakePHP: 1.1 and 1.2 12 Summary 12
A Quick Installation 13 Downloading CakePHP 13 Platform Requirements 17 Configuring Apache 17 AllowOverwrite is Set to All 17 Mod_rewrite Module is Loaded 18 Setting Up Cake in Web Root 18 Running Cake for the First Time 20 Summary 20 A Quick App 21 Making Sure the Oven is Ready 22 CakeTooDoo: a Simple To-do List Application 22 Configuring Cake to Work with a Database 23 Writing our First Model 25 Writing our First Controller 27 Viewing All Tasks in CakeTooDoo 29 Adding a New Task 32 Editing a Task 36 Adding Data Validation 39 Deleting a Task from CakeTooDoo 40 Viewing Completed Tasks and Pending Tasks 42 Formatting Date and Time 44 Creating the CakeTooDoo Homepage 45 Summary 47 Controllers: Programming Application Logic 49 Interacting with Model 50 Attaching Models and Controllers 50 Action, Parameters, and Views 52 Interacting with View 53 Actions and Parameters 55 Getting Post Data from the View 61 Redirecting 63 AppController: The Parent Controller 65 Working with Components 68 Summary 71 Models: Accessing Data 73 Setting Up Database and Models 74 Creating a Model for a Database Table 74 Retrieving Data 79 Using Model to Retrieve Data 79
More on Data Retrieval 82 Saving and Updating Data 91 Saving Data 91 Updating a Record 95 More on the save() Method 101 Updating a Single Field 102 Batch Update 102 Deleting Data 103 Deleting a Single Record 103 Placing Your Own Logic Inside Model 106 Create and Use Your Own Model Method 107 Validating Your Data 112 Adding Validation to Our Model 112 Summary 118 ORM: Modelling the Table Relationship 119 Working with Simple Associations 120 Defining One-To-Many Relationship in Models 120 Retrieving Related Model Data in One-To-Many Relation 123 Saving Related Model Data in One-To-Many Relation 128 Adding More than One Association of the Same Type 131 One-To-One Relation 132 Customizing Association Characteristics 133 Working with Complex Associations 134 Defining Many-To-Many Relationship in Models 134 Retrieving Related Model Data in Many-To-Many Relation 137 Saving Related Model Data in Many-To-Many Relation 140 Deleting Associated Data 141 Changing Association On The Fly 142 Summary 143 Views: Creating User Interfaces 145 Working with Layouts 146 Creating Custom Layouts 146 Using Elements 152 Creating and Using Element 152 Working with Helpers 156 Creating and Using Your Own Helper 157 Creating Forms to Take User Input 160 Summary 164
Using Shells: Get Further. Faster 165 Setting Up the Cake Shell 166 Setting Up the Cake Shell in Windows 166 Setting Up the Cake Shell in *nix 168 Baking an Application 170 Creating and Configuring the Database 170 Baking Models 174 Baking Controllers 181 Baking Views 186 Summary 191 Making Quickwall: The Basics 193 What is This Quickwall All About? 194 Setting Up Cake 194 Creating and Connecting the Database 196 Creating and Defining Relationships between Models 199 Creating the Basic Controller Actions and Their Views 201 Adding Custom Layout 207 Adding Forms to Add New Questions and Answers 215 Summary 223 Quickwall: User Authentication 225 Creating the User Model and the Users Controller 226 Making the User Sign Up Process 229 Adding Email Confirmation to Sign Up 238 Integrating Authentication: Database and Models 245 Integrating Authentication: Controllers 249 Integrating Authentication: Views 254 Remembering User with Cookie 259 Summary 264 Quickwall: JavaScript and AJAX 265 Adding JavaScript Validation 265 AJAX Link to Show Own Questions 270 AJAX AutoComplete to Search Users 276 AJAX Form Submit to View Questions of a User 281 In-Line Editing to Edit Own Answers 284 Summary 287 2g9_ Quickwall: Making It Better Making Dates More Readable 289 Creating a User Page 293 Linking the Search Page to the User Page 298
Adding Pagination 299 Adding RSS Feeds 302 Summary 306 Index 307