Cakephp Classroom image

To post your Question Join Classroom
Lesson Topics's No:-  |1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9|Last

Controllers are the ‘C’ in MVC. After routing has been applied and the correct controller has been found,
your controller’s action is called. Your controller should handle interpreting the request data, making sure
the correct models are called, and the right response or view is rendered. Controllers can be thought of as
middle man between the Model and View. You want to keep your controllers thin, and your models fat. This
will help you more easily reuse your code and makes your code easier to test.
Commonly, controllers are used to manage the logic around a single model. For example, if you were
building a site for an on-line bakery, you might have a RecipesController and an IngredientsController
managing your recipes and their ingredients. In CakePHP, controllers are named after the primary model
they handle. It’s totally possible to have controllers work with more than one model as well.
Your application’s controllers extend AppController class, which in turn extends
the core Controller class. The AppController class can be defined in
/app/Controller/AppController.php and it should contain methods that are shared between all
of your application’s controllers.
Controllers provide a number of methods which are called actions. Actions are methods on a controller
that handle requests. By default all public methods on a controller are an action, and accessible from a url.
Actions are responsible for interpreting the request and creating the response. Usually responses are in the
form of a rendered view, but there are other ways to create responses as well.
The App Controller
As stated in the introduction, the AppController class is the parent class to all of your application’s controllers.
AppController itself extends the Controller class included in the CakePHP core library. As such,
AppController is defined in /app/Controller/AppController.php like so:
class AppController extends Controller {
Controller attributes and methods created in your AppController will be available to all of your application’s
controllers. It is the ideal place to create code that is common to all of your controllers. Components (which
you’ll learn about later) are best used for code that is used in many (but not necessarily all) controllers.CakePHP Cookbook Documentation, Release 2.x
While normal object-oriented inheritance rules apply, CakePHP does a bit of extra work when it comes to
special controller attributes. The list of components and helpers used by a controller are treated specially.
In these cases, AppController value arrays are merged with child controller class arrays. The values in the
child class will always override those in AppController.
Note: CakePHP merges the following variables from the AppController to your application’s controllers:
• $components
• $helpers
• $uses
Remember to add the default Html and Form helpers, if you define var $helpers in your AppController
Please also remember to call AppController’s callbacks within child controller callbacks for best results:
public function beforeFilter() {



Skills    Cakephp

Qualifications :-
Location :-,,,

  Students (0)