Matthew Weier O'Phinney
code|works, Madison, WI
6 December 2012
get '/hello/:name' do [n]
"Hello #{n}!"
end
post '/address'
# create address
end
get '/feed.?:format?', :provides => ['rss', 'atom'] do
builder :feed
end
get('/hello/:name', function ($n) {
return "Hello {$n}!";
});
post('/address', function () {
// create address
});
get('/feed.?:format?', function ($feed, $format) {
return builder($feed, $format);
});
$app->get('/hello/:name', function ($n) {
return "Hello {$n}!";
});
$app->post('/address', function () {
// create address
});
$app->get('/feed.?:format?',
function ($feed, $format) use ($app) {
return $app->builder($feed, $format);
}
);
$app
Single value object passed to controllers
$app->get('/feed.:format', function ($params) {
$format = $params['format'];
// do some work ...
});
Pass the $app
to the controller
$app->get('/feed.:format', function ($app) {
$format = $app->params('format', 'DefaultValue?');
// do some work ...
});
Curry the $app
into the controller
$app->get('/feed.:format', function () use ($app) {
$format = $app->params('format', 'DefaultValue?');
// do some work ...
});
$app
.Return an object on creation, and manipulate it
$app->get('/feed.:format', function ($app) {
// do some work ...
})->constraints(['format' => '/^(atom|json)$/'])
->via('get', 'post') // choose multiple methods!
->name('feed');
// URL generation
$url = $app->urlFor('feed', ['format' => 'json']);
// Redirection
$app->redirect($url);
// Events
$app->trigger('update', $app->params()->getParams());
// Views
return $app->render('pages/foo');
Use small things that work together to solve larger problems.
curl -s https://getcomposer.org/installer \
> -o installer.php
php installer.php
packagist.org
Create composer.json
{
"require": {
"php": ">=5.3.3",
"phly/mustache": ">=1.2.0"
}
}
php composer.phar install
vendor/
by defaultzendframework/zend-mvc
- provides a Router
subcomponentsymfony/routing
aura/router
zendframework/zend-http
symfony/http-kernel
aura/http
zendframework/zend-view
twig/twig
phly/mustache
json_encode()
...Zend\View
or
aura/view
; Twig is a nice, full-featured templating engine; mustache is
useful in particular if you're also using it in your client-side logic; etc.Dependencies:
{
"require": {
"php": ">=5.4.0",
"zendframework/zend-escaper": "2.0.*",
"zendframework/zend-eventmanager": "2.0.*",
"zendframework/zend-http": "2.0.*",
"zendframework/zend-i18n": "2.0.*",
"zendframework/zend-log": "2.0.*",
"zendframework/zend-mvc": "2.0.*",
"zendframework/zend-session": "2.0.*",
"phly/mustache": ">=1.2.0",
}
Hello, World:
use Phlyty\App;
include 'vendor/autoload.php';
$app = new App();
$app->get('/', function ($app) {
echo "Hello, world!";
});
$app->run();
Features:
pass()
on to next matching route, stop()
, or halt()
Table of contents | t |
---|---|
Exposé | ESC |
Autoscale | e |
Full screen slides | f |
Presenter view | p |
Source files | s |
Slide numbers | n |
Blank screen | b |
Notes | 2 |
Help | h |