Wednesday, 23 November 2011

Structure of CakePHP

CakePHP features Controller, Model, and View classes, but it also features some additional classes and objects that make development in MVC a little quicker and more enjoyable. Components, Behaviors, and Helpers are classes that provide extensibility and reusability to quickly add functionality to the base MVC classes in your applications.

1- Components--A Component is a class that aids in controller logic. If you have some logic you want to share between controllers (or applications), a component is usually a good fit.
    As an example, create a email-component and use this email component to different controller,no need to create sap rate function in each controller.
2- Helpers--A Helper is a class that aids in view logic. Much like a component used among controllers, helpers allow presentational logic to be accessed and shared between views. One of the core helpers, AjaxHelper, makes Ajax requests within views much easier.
Most applications have pieces of view code that are used repeatedly. CakePHP facilitates view code reuse with layouts and elements. By default, every view rendered by a controller is placed inside a layout. Elements are used when small snippets of content need to be reused in multiple views.
   
     An example ---   it is declare in app_controller:-
                               var $helpers = array('Form','Html','Javascript','Session');
3- Behaviors--Similar to Components and Helpers, "Behaviors" work as ways to add common functionality between models.

4- Application Extensions--Controllers, helpers and models each have a parent class you can use to define application-wide changes. AppController (located at /app/app_controller.php), AppHelper (located at /app/app_helper.php) and AppModel (located at /app/app_model.php) are great places to put methods you want to share between all controllers, helpers or models.

1 comment:

  1. Most of the blogs pretend themselves as most usable and updated blogs with new information but sometime truth might different. I want to share some facts related to this subject which will help people to enhance their skills.iOS-Android

    ReplyDelete