Cakephp using basic MVC Architecture and it resolves the structural forms (eg. Form Handling) in new Version 1.3.
Models :- Models represent data and are used in CakePHP applications for data access. Used for Communicating View and Controller. (Ex. Database Connection,Table,Query Dealings).
Controller :- A controller is used to manage the logic for a part of your application. Most commonly, controllers are used to manage the logic for a single model.It represents the Core Part of the MVC.
Views :- Views are responsible for generating the specific output required for the request. Often this is in the form of HTML, XML, or JSON, but streaming files and creating PDF's that users can download are also responsibilities of the View Layer.
Apart from this basic Architecture, we need more tools to create a MVC World, like
Components :-Components are packages of logic that are shared between controllers. If you find yourself wanting to copy and paste things between controllers, you might consider wrapping some functionality in a component.
CakePHP also comes with a fantastic set of core components you can use to aid in:
- Security
- Sessions
- Access control lists
- Emails
- Cookies
- Authentication
- Request handling
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.
Controllers are also fitted with callbacks. These callbacks are available for your use, just in case you need to insert some logic between CakePHP’s core operations. Callbacks available include:
beforeFilter(), executed before any controller action logicbeforeRender(), executed after controller logic, but before the view is renderedafterFilter(), executed after all controller logic, including the view render. There may be no difference betweenafterRender()andafterFilter()unless you’ve manually made a call torender()in your controller action and have included some logic after that call.
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.
Model Extensions ("Behaviors")
Similar to Components and Helpers, "Behaviors" work as ways to add common functionality between models. For example, if you store user data in a tree structure, you can specify your "User" model as behaving like a tree, and gain free functionality for removing, adding, and shifting nodes in your underlying tree structure.Just like controllers, models are featured with callbacks as well:
- beforeFind()
- afterFind()
- beforeValidate()
- beforeSave()
- afterSave()
- beforeDelete()
- afterDelete()
File and Classname Conventions
In general, filenames are underscored while classnames are CamelCased. So if you have a class MyNiftyClass, then in Cake, the file should be named my_nifty_class.php. Below are examples of how to name the file for each of the different types of classes you would typically use in a CakePHP application:- The Controller class KissesAndHugsController would be found in a file named kisses_and_hugs_controller.php (notice _controller in the filename)
- The Component class MyHandyComponent would be found in a file named my_handy.php
- The Model class OptionValue would be found in a file named option_value.php
- The Behavior class EspeciallyFunkableBehavior would be found in a file named especially_funkable.php
- The View class SuperSimpleView would be found in a file named super_simple.php
- The Helper class BestEverHelper would be found in a file named best_ever.php
No comments:
Post a Comment