Upload
mike-myat-min-han
View
2.559
Download
2
Embed Size (px)
DESCRIPTION
Citation preview
Hi!
Saturday, 19 January, 13
I’m Myat Min Han aka Mike@mmhan
http://mmhan.net
Saturday, 19 January, 13
Introduction to MVC & CakePHP
BarCamp Yangon 2013
Saturday, 19 January, 13
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
MVC
Saturday, 19 January, 13
To Show a random Joke
Saturday, 19 January, 13
To Show a random Joke
Saturday, 19 January, 13
1 - Browser Sends Request
To Show a random Joke
Saturday, 19 January, 13
1 - Browser Sends Request
2 - Controller ask for a random Joke
To Show a random Joke
Saturday, 19 January, 13
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
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
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
In a nutshell
Model - Business LogicController - Handling Transactions and requestsView - Presentation Layer
Saturday, 19 January, 13
CakePHP
Saturday, 19 January, 13
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
Creating a WebAppAwesome Random Joke
Saturday, 19 January, 13
Download CakePHP Framework
Download from http://cakephp.org
Or git clone git://github.com/cakephp/cakephp.git random_jokes
Saturday, 19 January, 13
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
Configuring Databaseapp/Config/database.php
Saturday, 19 January, 13
Checkout the sitehttp://localhost/random_jokes/
Saturday, 19 January, 13
Let’s start baking
In Console (Or Command Prompt)
Saturday, 19 January, 13
Follow the instructions
Saturday, 19 January, 13
GeneratedList : http://localhost/random_jokes/jokes/
Saturday, 19 January, 13
GeneratedNew: http://localhost/random_jokes/jokes/add/
Saturday, 19 January, 13
GeneratedEdit: http://localhost/random_jokes/jokes/edit/<id>
Saturday, 19 January, 13
GeneratedView: http://localhost/random_jokes/jokes/view/<id>
Saturday, 19 January, 13
Blank jokes
Saturday, 19 January, 13
Edit the Model fileapp/Model/Joke.php
Add validation rules
Saturday, 19 January, 13
Give it a tryNew: http://localhost/random_jokes/jokes/add/
Saturday, 19 January, 13
Showing Random Joke
Saturday, 19 January, 13
Showing Random Jokeapp/Model/Joke.php
Add the business logic to model
Saturday, 19 January, 13
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
Showing Random Jokeapp/View/Jokes/random.ctp
Create view file
Saturday, 19 January, 13
Try it outhttp://localhost/random_jokes/jokes/random
Saturday, 19 January, 13
Features
Saturday, 19 January, 13
Features
Baking: Code GenerationConvention over ConfigurationActive RecordSecure by Default
Saturday, 19 January, 13
And many other features
I18n
Caching
Access Control List
Authentication
Pagination
and lots of others...
Saturday, 19 January, 13
Read More
About MVC - http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
CakePHP Official Site - http://cakephp.org
Cake Book - Reference material for all things CakePHP - http://book.cakephp.org
Plugins - http://plugins.cakephp.org/
Saturday, 19 January, 13
Thank You!
Saturday, 19 January, 13