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...