get going with cakephp framework at gnunify 2010

Download Get going with CakePHP Framework at gnuNify 2010

If you can't read please download the document

Upload: abbas-ali

Post on 16-Apr-2017

3.785 views

Category:

Technology


3 download

TRANSCRIPT

Get going with CakePHP Framework

ByAbbas AliSANIsoft Technologies,Nagpur

I am...

Mechanical Engineer

Technical Manager with SANIsoft

Dev Team member of Coppermine Photo Gallery

FOSS Enthusiast

Mechanical Engineer by education and graduated from Nagpur University in 2003

Fascinated with both machines and computers

Working in PHP since last 6 years. Was a career choice but soon became obsession

Got acquainted with cakephp sometime in 2005 and started using it in commercial project from 2006 onwards

Roadmap...

What is a Web application framework

What is CakePHP and its History

Features

Model, controller and view

Helpers, components and behaviors

What is a Web Framework?

A web application framework is a software framework that is designed to support the development of dynamic websites, Web applications and Web services.(Wikipedia)

The framework aims to alleviate the overhead associated with common activities performed in Web development. For example, many frameworks provide libraries for database access, templating frameworks and session management, and they often promote code reuse.

Helps in rapid application development as code is reused and common tasks are performed by the framework. Ex: html/form helpers, db abstraction, auth component

A library is a set of classes or functions which are invoked by your code while a framework has an inbuilt architecture, which dictates the way an application has to be written to use it. The framework invokes your code.

CakePHP!!!

R.A.D framework

For PHP written in PHP

MVC architectural pattern

ORM design pattern

Convention over Configuration

We can create application rapidly. A add form which normally takes 0.5 to 1 hr can be done within 10 mins and less than 50 lines of code

You can actually see how a particular method works as it is written in php

MVC will be explained in later slide

ORM maps objects to relational database where an attribute maps to columns in database. Some attribute holds objects of other tables. Example Addressbook with multiple addresses for each user and multiple phone numbers

If convention is followed then no configuration is needed

History

Michal Tatarynowicz - April 15th 2005

Larry E. Masters (aka phpnut) took over in July 2005

v1.0 was released on May 1st 2006

Current stable release v1.2.6

Cake3 => Li3

Michal Tatarynowicz wrote a minimal version of a Rapid Application Framework in PHP and found that it was the start of a very good framework. Michal published the framework under The MIT license, dubbing it Cake, and opened it up to a community of developers, who now maintain Cake under the name

Heavy development during 2005-2006 to release a stable version

The team created bakery, cakeforge and bin

CakePHP is not a port of Ruby on Rails to PHP, but appropriates many of its useful concepts.From chat logs: Cake is building a well documentated framework inspired by the concepts introduced in Ruby On Railshttp://stackoverflow.com/questions/1432729/is-cakephp-modeled-after-ruby-on-rails

Why CakePHP?

No Configuration - Set-up the database and let the magic begin

Extremely Simple - Just look at the name...It's Cake

Active, Friendly Community

Best Practices - covering security, authentication, and session handling, among the many other features

OO - Whether you are a seasoned object-oriented programmer or a beginner, you'll feel comfortable

More Features

Application Scaffolding

Code generation via Bake

Helpers for HTML, Forms, Pagination, AJAX, Javascript, XML, RSS and more

Access Control Lists and Authentication

Simple yet extensive validation of model data

Router for mapping urls

Scaffolding is used for generating code on the fly for CRUD of a database table - http://en.wikipedia.org/wiki/Scaffold_(programming)

Validation is done before saving a record and if validation fails error messages are shown. Multiple validation rule per field can be applied

ACL is authorization which is different from authentication. Being Authenticated does not automatically mean Authorized, but being Authorized would have to mean you are Authenticated.

Explain routing with an example http://localhost/controller/action/

How to?

Installation

Download (http://cakephp.org)

Unpack

Put it in webroot

That is it....

mod_rewrite needs to be enabled

Make tmp directory writable and change the value of security salts recommended but not necessary

Open http://example.com and this should show the welcome page

Three ways to install cakephp Development (in a subfolder) Production (root of website) Advanced (share the cake library folder)

Directory Structure

|-- app|-- cake|-- vendors|-- .htaccess`-- index.php

|-- app| |-- config| |-- controllers| |-- models| |-- views| `-- webroot| |-- .htaccess| |-- index.phpThe app folder will be where you work your magic: its where your applications files will be placed.

The cake folder is where cake have worked its magic. Make a personal commitment not to edit files in this folder. Cake cant help you if youve modified the core.

Finally, the vendors folder is where youll place third-party PHP libraries you need to use with your CakePHP applications.

A typical request

The MVC paradigm is a way of breaking an application, or even just a piece of an application's interface, into three parts: the model, the view, and the controller. MVC was originally developed to map the traditional input, processing, output roles into the GUI realm

The Model represents the application dataThe View renders a presentation of model dataThe Controller handles and routes requests made by the client

Why use MVC? Because it is a tried and true software design pattern that turns an application into a maintainable, modular, rapidly developed package.Allows developers and designers to work simultaneously

Conventions

In general, filenames are underscored while classnames are CamelCased

Model classnames are singular and CamelCased.

Controller classnames are plural, CamelCased, and end in Controller.

View template files are named after the controller functions they display, in an underscored form.

mod_rewrite needs to be enabled

Make tmp directory writable and change the value of security salts recommended but not necessary

Open http://example.com and this should show the welcome page

Three ways to install cakephp Development (in a subfolder) Production (root of website) Advanced (share the cake library folder)

Model

Controller

print_r($articles);

Array( [0] => Array ( [Article] => Array ( [id] => 1 [title] => first article [content] => gnunify rocks!!! ) ) [1] => ......)

View

Helpers

Other Goodies...

ComponentsAuth

Session

Cookie

BehaviorsTree

Containable

Summing Up

With CakePHP you can rapidly develop an application which is secure, scalable and easy to maintain.

References and further reading

http://en.wikipedia.org

http://book.cakephp.org

http://bakery.cakephp.org

Thank You

class Question extends Curiosity{var $ask = easy ones please;}