Book Image

CakePHP Application Development

By : Ahsanul Bari, Anupom Syam
Book Image

CakePHP Application Development

By: Ahsanul Bari, Anupom Syam

Overview of this book

<p>Cake is a rapid development framework for PHP that uses well-known design patterns and provides a structured framework that enables PHP users at all levels to rapidly develop robust web applications, without any loss of flexibility. It means you can code faster, your code is better, and it makes writing Web 2.0-style apps a snap.<br /><br />This book offers step-by-step instructions to learn the CakePHP framework and to quickly develop and deploy web-based applications. It introduces the MVC pattern and coding styles using practical examples. It takes the developer through setting up a CakePHP development and deployment environment, and develops an example application to illustrate all of the techniques you need to write a complete, non-trivial application in PHP. It aims to assist PHP programmers to rapidly develop and deploy well-crafted and robust web-based applications with CakePHP.</p>
Table of Contents (18 chapters)
CakePHP Application Development
Credits
About the Authors
About the Reviewer
Preface
Index

AppController: The Parent Controller


From Object Oriented perspective, every CakePHP controller is a subclass of the AppController class. Recall how we start the class definition of a controller—look at the following line of code as an example:

class BooksController extends AppController {

Our controllers extend the AppController class—this means we set the AppController class as the parent class of all of our controllers. As of now, it seems alright. But the next question that quickly pops up in our mind is: where is that AppController class located? Well, it can be found inside the app_controller.php file under the /cake/libs/controller/ directory. This app_controller.php is actually a placeholder file and can be overridden by our own one.

The main benefit of having our own AppController class is we can put in common application-wide methods inside this class and all of our controllers will just inherit them. We can use attributes and methods defined inside the AppController from any...