Showing posts with label Introduction of cakephp. Show all posts
Showing posts with label Introduction of cakephp. Show all posts

Nov 25, 2011

Core Helpers in Cakephp


Helpers
Helpers represent component-like classes for the presentation layer of your application, which contain presentational logic shared between many views, elements or layouts.

The CakePHP framework needs a controller in order to make usage of helpers. Each controller has a $helpers property that lists the helpers to be made available in the view. To enable a helper in your view, add the name of the helper to the controller’s $helpers array.


Example


<?php
class ExampleController extends AppController {
var $name = 'Example';
var $helpers = array('Html','Ajax','Javascript');
}

CakePHP features a number of helpers that aid in view creation. They assist in creating well-formed markup (including forms), aid in formatting text, times and numbers, and can even speed up Ajax functionality. Here is a summary of the built-in helpers.
CakePHP Helper
Description
Ajax
Used in tandem with the Prototype JavaScript library to create Ajax functionality in views. Contains shortcut methods for drag/drop, ajax forms & links, observers, and more.
Cache
Used by the core to cache view content.
Form
Creates HTML forms and form elements that self populate and handle validation problems.
Html
Convenience methods for crafting well-formed markup. Images, links, tables, header tags and more.
Js
Used to create Javascript compatible with various Javascript libraries. Replaces JavascriptHelper and AjaxHelper with a more flexible solution.
Used to escape values for use in JavaScripts, write out data to JSON objects, and format code blocks.
Number
Number and currency formatting.
Model data pagination and sorting.
Convenience methods for outputting RSS feed XML data.
Session
Access for reading session values in views.
Text
Smart linking, highlighting, word smart truncation.
Time
Proximity detection (is this next year?), nice string formatting(Today, 10:30 am) and time zone conversion.
Xml
Convenience methods for creating XML headers and elements.

 *if any type of help is needed regarding prog or concept contact me on dadhich.priyank@gmail.com


Nov 21, 2011

APPROACH TO THE MVC ARCHITECTURE

 Cake is based on an MVC-like architecture that is both powerful and easy to grasp: controllers, models and views guarantee a strict but natural separation of business logic from data and presentation layers.

Controllers contain the logic of your application. Each controller can offer different functionality; controllers retrieve and modify data by accessing database tables through models; and they register variables and objects, which can be used in views.

Models are active representations of database tables: they can connect to your database, query it (if instructed to do so by a controller) and save data to the database. It is important to note that in order to correctly apply the MVC architecture, there must be no interaction between models and views: all the logic is handled by controllers.


Views can be described as template files(means that contans the html or designs) that present their content to the user: variables, arrays and objects that are used in views are registered through a controller. Views should not contain complex business logic; only the elementary control structures necessary to perform particular operations, such as the iteration of collected data through a foreach construct, should be contained within a view.

This architecture can greatly improve the maintainability and the organization of your site’s code:

It separates business logic from presentation and data retrieval.
A site is divided into logical sections, each governed by a particular controller.
When testing and debugging an application, any developer accustomed to CakePHP’s structure will be able to locate and correct errors without knowing all of the details of the code.
Controllers, models and views are stored in pre-defined directories within CakePHP’s directory structure. Here’s the directory structure that’s used:

app/
config/
controllers/
models/
plugins/
tmp/
vendors/
views/
webroot/
cake/
config/
docs/
libs/
vendors/
This directory scheme must be preserved, as it is essential if the framework itself is to work. Cake, like Rails, believes in the importance of convention over configuration: in order to deploy an application, rather than modify dozens of different configuration files, it’s important only to place everything in its proper place; then, you can let the framework do the rest.

Although this may seem worrisome for some developers, it’s a good compromise that can really accelerate the development process.


Enjoy