Introduction MVC & CakePHP

39
Hi! Saturday, 19 January, 13

description

 

Transcript of Introduction MVC & CakePHP

Page 1: Introduction MVC & CakePHP

Hi!

Saturday, 19 January, 13

Page 2: Introduction MVC & CakePHP

I’m Myat Min Han aka Mike@mmhan

http://mmhan.net

Saturday, 19 January, 13

Page 3: Introduction MVC & CakePHP

Introduction to MVC & CakePHP

BarCamp Yangon 2013

Saturday, 19 January, 13

Page 4: Introduction MVC & CakePHP

I’m going to assume:You don’t know MVC and CakePHPYou know PHPYou (or want to) develop web applicationsYou want to deliver a project quickly.

Saturday, 19 January, 13

Page 5: Introduction MVC & CakePHP

MVC

Saturday, 19 January, 13

Page 6: Introduction MVC & CakePHP

To Show a random Joke

Saturday, 19 January, 13

Page 7: Introduction MVC & CakePHP

To Show a random Joke

Saturday, 19 January, 13

Page 8: Introduction MVC & CakePHP

1 - Browser Sends Request

To Show a random Joke

Saturday, 19 January, 13

Page 9: Introduction MVC & CakePHP

1 - Browser Sends Request

2 - Controller ask for a random Joke

To Show a random Joke

Saturday, 19 January, 13

Page 10: Introduction MVC & CakePHP

1 - Browser Sends Request

2 - Controller ask for a random Joke3 - Controller

Receives a random joke

To Show a random Joke

Saturday, 19 January, 13

Page 11: Introduction MVC & CakePHP

1 - Browser Sends Request

2 - Controller ask for a random Joke3 - Controller

Receives a random joke

4 - Controller sends the Joke to View

To Show a random Joke

Saturday, 19 January, 13

Page 12: Introduction MVC & CakePHP

1 - Browser Sends Request

2 - Controller ask for a random Joke3 - Controller

Receives a random joke

4 - Controller sends the Joke to View

5 - View shows the joke to browser.

To Show a random Joke

Saturday, 19 January, 13

Page 13: Introduction MVC & CakePHP

In a nutshell

Model - Business LogicController - Handling Transactions and requestsView - Presentation Layer

Saturday, 19 January, 13

Page 14: Introduction MVC & CakePHP

CakePHP

Saturday, 19 January, 13

Page 15: Introduction MVC & CakePHP

What is CakePHP?

Open-source MVC PHP Development Framework for web applications.Modeled after concepts of Ruby on RailsReleased in 2005

Saturday, 19 January, 13

Page 16: Introduction MVC & CakePHP

Creating a WebAppAwesome Random Joke

Saturday, 19 January, 13

Page 17: Introduction MVC & CakePHP

Download CakePHP Framework

Download from http://cakephp.org

Or git clone git://github.com/cakephp/cakephp.git random_jokes

Saturday, 19 January, 13

Page 18: Introduction MVC & CakePHP

Create a table in a new database

CREATE DATABASE `awesome_jokes`;

CREATE TABLE `jokes` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(150) DEFAULT NULL, `body` text, `created` datetime DEFAULT NULL, `modified` datetime DEFAULT NULL, PRIMARY KEY (`id`));

Saturday, 19 January, 13

Page 19: Introduction MVC & CakePHP

Configuring Databaseapp/Config/database.php

Saturday, 19 January, 13

Page 20: Introduction MVC & CakePHP

Checkout the sitehttp://localhost/random_jokes/

Saturday, 19 January, 13

Page 21: Introduction MVC & CakePHP

Let’s start baking

In Console (Or Command Prompt)

Saturday, 19 January, 13

Page 22: Introduction MVC & CakePHP

Follow the instructions

Saturday, 19 January, 13

Page 23: Introduction MVC & CakePHP

GeneratedList : http://localhost/random_jokes/jokes/

Saturday, 19 January, 13

Page 24: Introduction MVC & CakePHP

GeneratedNew: http://localhost/random_jokes/jokes/add/

Saturday, 19 January, 13

Page 25: Introduction MVC & CakePHP

GeneratedEdit: http://localhost/random_jokes/jokes/edit/<id>

Saturday, 19 January, 13

Page 26: Introduction MVC & CakePHP

GeneratedView: http://localhost/random_jokes/jokes/view/<id>

Saturday, 19 January, 13

Page 27: Introduction MVC & CakePHP

Blank jokes

Saturday, 19 January, 13

Page 28: Introduction MVC & CakePHP

Edit the Model fileapp/Model/Joke.php

Add validation rules

Saturday, 19 January, 13

Page 29: Introduction MVC & CakePHP

Give it a tryNew: http://localhost/random_jokes/jokes/add/

Saturday, 19 January, 13

Page 30: Introduction MVC & CakePHP

Showing Random Joke

Saturday, 19 January, 13

Page 31: Introduction MVC & CakePHP

Showing Random Jokeapp/Model/Joke.php

Add the business logic to model

Saturday, 19 January, 13

Page 32: Introduction MVC & CakePHP

Showing Random Jokeapp/Controller/JokesController.php

Add a new action (method) to JokesController class to create the a new url for your app

and retrieve random joke to show it on view http://localhost/random_jokes/jokes/random

Saturday, 19 January, 13

Page 33: Introduction MVC & CakePHP

Showing Random Jokeapp/View/Jokes/random.ctp

Create view file

Saturday, 19 January, 13

Page 34: Introduction MVC & CakePHP

Try it outhttp://localhost/random_jokes/jokes/random

Saturday, 19 January, 13

Page 35: Introduction MVC & CakePHP

Features

Saturday, 19 January, 13

Page 36: Introduction MVC & CakePHP

Features

Baking: Code GenerationConvention over ConfigurationActive RecordSecure by Default

Saturday, 19 January, 13

Page 37: Introduction MVC & CakePHP

And many other features

I18n

Caching

Access Control List

Authentication

Email

Pagination

and lots of others...

Saturday, 19 January, 13

Page 39: Introduction MVC & CakePHP

Thank You!

Saturday, 19 January, 13