CakePHP 1.3 Application Development Cookbook.pdf

时间:2022-09-07 04:37:40
【文件属性】:

文件名称:CakePHP 1.3 Application Development Cookbook.pdf

文件大小:6.21MB

文件格式:PDF

更新时间:2022-09-07 04:37:40

CakePHP Application Development Cookbook

Preface 3 Chapter 6, Routing Magic: Almost every web-based application will eventually have to develop a successful strategy to obtain better search engine position through a technique known as search engine optimization. This chapter starts by introducing some basic concepts of routing through the use of route parameters, and continues to build optimized routes to leverage our search engine placement. The final section in this chapter shows us how to create highly optimized URLs for our user profiles, and how to build custom Route classes to obtain even more flexibility. Chapter 7, Creating and Consuming Web Services: Web services are essential when looking forward to expose application functionality to third-party applications, or when looking forward to integrate foreign services into our own applications. They offer a broad set of technologies and definitions so systems written in different programming languages can communicate. This chapter introduces a set of recipes to consume web services and to expose parts of our application as web services. Chapter 8, Working with Shells: One of the most powerful, yet unknown, features of CakePHP is its shell framework. It provides applications with all that is required for building command line tools, which can be used to perform intensive tasks and any other type of non interactive processing. This chapter introduces the reader to CakePHP shells by starting with the process of building basic shells, and then moving on to more advanced features, such as sending e-mails, and running controller actions from shells. It finishes by presenting the robot plugin, which offers a fully featured solution for scheduling and running tasks. Chapter 9, Internationalizing Applications: This chapter includes a set of recipes that allow the reader to internationalize all aspects of their CakePHP applications, including static content (such as those available in views), and dynamic content (such as database records). The first two recipes show how to allow text that is part of any CakePHP view, or model validation messages, to be ready for translation. The third recipe shows how to translate more complex expressions. The fourth recipe shows how to run CakePHP's built in tools to extract all static content that needs translation, and then translate that content to different languages. The fifth recipe shows how to translate database records. Finally, the last recipe shows how to allow users to change the current application language. Chapter 10, Testing: This chapter covers one of the most interesting areas of application programming: unit testing through CakePHP's built-in tools, which offers a complete and powerful unit testing framework. Download from Wow! eBook Preface 4 The first recipe shows how to set up the test framework so that we can create our own test cases. The second recipe shows how to create test data (fixtures) and use that data to test model methods. The third and fourth recipes show how to test controller actions, and how to test that our views are showing what we expect. The last recipe shows how to run the test in a non-ordinary fashion. Chapter 11, Utility Classes and Tools: This chapter introduces a set of utility classes and helpful techniques that improve the architecture of a CakePHP application. The first recipe shows how to work with a CakePHP class that optimizes the manipulation of arrays. The second recipe shows how to send an e-mail using the Email component. The third recipe shows how to use the MagicDb class to detect the type of a file, and the last recipe shows how to create application exceptions, and properly handle them when they are thrown. What you need for this book We need the following software for the book: f A web server supported by CakePHP (such as Apache) f A database engine supported by CakePHP (such as MySQL) f CakePHP installed, configured, and working properly Who this book is for If you are a CakePHP developer who wants to discover quick and easy ways to improve web applications, and to leverage all aspects of the framework, this book is for you. This book assumes that you already have knowledge of CakePHP and general PHP development skills. Conventions In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning. Code words in text are shown as follows: "Create a file named query_log.php and place it in your app/controllers/components folder with the following contents:" 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 will 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 (which show how to work with AJAX, datasources, GEO location, routing, performance optimization, and more), you will be able to understand and use these features in no time. What this book covers Chapter 1, Authentication: This chapter explains how to set up authentication on a CakePHP application, starting from the most basic setup and finishing with advanced authorization mechanisms. This is accomplished through the use of tools that are built into the framework core, which allow us to quickly set up secure areas, without losing flexibility to build more complex solutions. The first two recipes show us how to set up a basic, yet fully working authentication system. The next three recipes allow our users to log in using different information, have their user details saved after a successful login, and show us how to get this user information. The sixth recipe shows a more complex authorization technique that relies on route prefixes. The seventh recipe sets up a complex authentication system through the use of CakePHP's Access Control Layer. Finally, the last recipe shows us how to integrate our application with OpenID. Chapter 2, Model Bindings: This chapter deals with one of the most important aspects of a CakePHP application: the relationship between models, also known as model bindings or associations. Being an integral part of any application's logic, it is of crucial importance that we master all aspects of how model bindings can be manipulated to get the data we need, when we need it. Preface 2 In order to do so, 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 Chapter 3, Pushing the Search: Using models to fetch data is one of the most important aspects of any CakePHP application. As such, a good use of the find functions the framework provides can certainly guarantee the success of our application, and as importantly ensure that our code is readable and maintainable. In this chapter, we have several recipes to resort to manual SQL-based queries when the need arises. CakePHP also lets us define our custom find types that will extend the basic ones, allowing our code to be even more readable. The last recipes in this chapter show us how to add pagination support to our find type. Chapter 4, Validation and Behaviors: This chapter deals with two aspects of CakePHP models that are fundamental to most applications: validation and behaviors. When we are saving information to a data source (such as a database), CakePHP will automatically ensure that the data is quoted in order to prevent attacks, SQL injection being the most common one. If we also need to ensure that the data follows a certain format (for example, that a phone number is valid), we use validation rules. There are also times where we need to do more than just validate the data we are working with. In some cases, we need to set values for fields that the end user can't specify but are part of our application logic. CakePHP's behaviors allow us to extend the functionality provided by a model, using callbacks to manipulate the data before it's saved, or after it's fetched. The third recipe shows us how to use model callbacks (such as beforeFind and afterFind) in behaviors, while the fourth recipe shows how to use behaviors to add additional field values when a save operation is being undertaken. The last two recipes in this chapter give examples on how to use the Sluggable behavior (for creating SEO friendly URLs), and the Geocodable behavior (to add geocoding support to an Address model). Chapter 5, Datasources: Datasources are the backbone of almost all model operations. They provide an abstraction between model logic and the underlying data layer, allowing a more flexible approach to data manipulation. Through this abstraction, CakePHP applications are able to manipulate data without knowing the specifics of how it's stored, or fetched. This chapter shows how to get information from existing datasources, use pre-built datasources to deal with non-relational data, and teaches us how to create a full-featured twitter datasource.


网友评论