|
| 1 | +diff --git a/bootstrap.php b/bootstrap.php |
| 2 | +index fa4ccc1..45ebf60 100644 |
| 3 | +--- a/bootstrap.php |
| 4 | ++++ b/bootstrap.php |
| 5 | +@@ -82,6 +82,13 @@ function _create_container() |
| 6 | + |
| 7 | + return $logger; |
| 8 | + }; |
| 9 | ++ $c['twig'] = function() { |
| 10 | ++ $loader = new \Twig_Loader_Filesystem(array( |
| 11 | ++ __DIR__.'/views' |
| 12 | ++ )); |
| 13 | ++ |
| 14 | ++ return new \Twig_Environment($loader); |
| 15 | ++ }; |
| 16 | + |
| 17 | + return $c; |
| 18 | + } |
| 19 | +\ No newline at end of file |
| 20 | +diff --git a/composer.json b/composer.json |
| 21 | +index b5634d1..a97c670 100644 |
| 22 | +--- a/composer.json |
| 23 | ++++ b/composer.json |
| 24 | +@@ -3,6 +3,7 @@ |
| 25 | + "symfony/http-foundation": "~2.5", |
| 26 | + "aura/router": "~2.1", |
| 27 | + "pimple/pimple": "~3.0", |
| 28 | +- "zendframework/zend-log": "~2.3" |
| 29 | ++ "zendframework/zend-log": "~2.3", |
| 30 | ++ "twig/twig": "~1.0" |
| 31 | + } |
| 32 | + } |
| 33 | +diff --git a/composer.lock b/composer.lock |
| 34 | +index 5dfd2c3..fdd8c16 100644 |
| 35 | +--- a/composer.lock |
| 36 | ++++ b/composer.lock |
| 37 | +@@ -4,7 +4,7 @@ |
| 38 | + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", |
| 39 | + "This file is @generated automatically" |
| 40 | + ], |
| 41 | +- "hash": "9c896a0d521571be9af54e819eef46e7", |
| 42 | ++ "hash": "c5d052620c8f3b93f99c1d889a185545", |
| 43 | + "packages": [ |
| 44 | + { |
| 45 | + "name": "aura/router", |
| 46 | +@@ -160,6 +160,63 @@ |
| 47 | + "time": "2014-10-24 05:49:22" |
| 48 | + }, |
| 49 | + { |
| 50 | ++ "name": "twig/twig", |
| 51 | ++ "version": "v1.16.2", |
| 52 | ++ "source": { |
| 53 | ++ "type": "git", |
| 54 | ++ "url": "https://github.com/twigphp/Twig.git", |
| 55 | ++ "reference": "42f758d9fe2146d1f0470604fc05ee43580873fc" |
| 56 | ++ }, |
| 57 | ++ "dist": { |
| 58 | ++ "type": "zip", |
| 59 | ++ "url": "https://api.github.com/repos/twigphp/Twig/zipball/42f758d9fe2146d1f0470604fc05ee43580873fc", |
| 60 | ++ "reference": "42f758d9fe2146d1f0470604fc05ee43580873fc", |
| 61 | ++ "shasum": "" |
| 62 | ++ }, |
| 63 | ++ "require": { |
| 64 | ++ "php": ">=5.2.4" |
| 65 | ++ }, |
| 66 | ++ "type": "library", |
| 67 | ++ "extra": { |
| 68 | ++ "branch-alias": { |
| 69 | ++ "dev-master": "1.16-dev" |
| 70 | ++ } |
| 71 | ++ }, |
| 72 | ++ "autoload": { |
| 73 | ++ "psr-0": { |
| 74 | ++ "Twig_": "lib/" |
| 75 | ++ } |
| 76 | ++ }, |
| 77 | ++ "notification-url": "https://packagist.org/downloads/", |
| 78 | ++ "license": [ |
| 79 | ++ "BSD-3-Clause" |
| 80 | ++ ], |
| 81 | ++ "authors": [ |
| 82 | ++ { |
| 83 | ++ "name": "Fabien Potencier", |
| 84 | ++ "email": "fabien@symfony.com", |
| 85 | ++ "homepage": "http://fabien.potencier.org", |
| 86 | ++ "role": "Lead Developer" |
| 87 | ++ }, |
| 88 | ++ { |
| 89 | ++ "name": "Armin Ronacher", |
| 90 | ++ "email": "armin.ronacher@active-4.com", |
| 91 | ++ "role": "Project Founder" |
| 92 | ++ }, |
| 93 | ++ { |
| 94 | ++ "name": "Twig Team", |
| 95 | ++ "homepage": "https://github.com/fabpot/Twig/graphs/contributors", |
| 96 | ++ "role": "Contributors" |
| 97 | ++ } |
| 98 | ++ ], |
| 99 | ++ "description": "Twig, the flexible, fast, and secure template language for PHP", |
| 100 | ++ "homepage": "http://twig.sensiolabs.org", |
| 101 | ++ "keywords": [ |
| 102 | ++ "templating" |
| 103 | ++ ], |
| 104 | ++ "time": "2014-10-17 12:53:44" |
| 105 | ++ }, |
| 106 | ++ { |
| 107 | + "name": "zendframework/zend-log", |
| 108 | + "version": "2.3.3", |
| 109 | + "target-dir": "Zend/Log", |
| 110 | +diff --git a/controllers.php b/controllers.php |
| 111 | +index 9adb562..4de8eb7 100644 |
| 112 | +--- a/controllers.php |
| 113 | ++++ b/controllers.php |
| 114 | +@@ -8,13 +8,10 @@ use Pimple\Container; |
| 115 | + * Define our controllers |
| 116 | + */ |
| 117 | + |
| 118 | +-function homepage_controller(Request $request) { |
| 119 | +- |
| 120 | +- $content = '<h1>PHP Camp!</h1>'; |
| 121 | +- $content .= '<a href="/attendees">See the attendees</a>'; |
| 122 | +- if ($name = $request->attributes->get('name')) { |
| 123 | +- $content .= sprintf('<p>Oh, and hello %s!</p>', $name); |
| 124 | +- } |
| 125 | ++function homepage_controller(Request $request, Container $c) { |
| 126 | ++ $content = $c['twig']->render('homepage.twig', array( |
| 127 | ++ 'name' => $request->attributes->get('name'), |
| 128 | ++ )); |
| 129 | + |
| 130 | + return new Response($content); |
| 131 | + } |
| 132 | +@@ -23,17 +20,11 @@ function attendees_controller(Request $request, Container $c) { |
| 133 | + $dbh = $c['connection']; |
| 134 | + |
| 135 | + $sql = 'SELECT * FROM php_camp'; |
| 136 | +- $content = '<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />'; |
| 137 | +- $content .= '<h1>PHP Camp Attendees</h1>'; |
| 138 | +- $content .= '<table class="table" style="width: 300px;">'; |
| 139 | +- foreach ($dbh->query($sql) as $row) { |
| 140 | +- $content .= sprintf( |
| 141 | +- '<tr><td style="font-size: 24px;">%s</td><td><img src="%s" height="120" /></td></tr>', |
| 142 | +- $row['attendee'], |
| 143 | +- $row['avatar_url'] |
| 144 | +- ); |
| 145 | +- } |
| 146 | +- $content .= '</table>'; |
| 147 | ++ $campers = $dbh->query($sql); |
| 148 | ++ |
| 149 | ++ $content = $c['twig']->render('attendees.twig', array( |
| 150 | ++ 'campers' => $campers |
| 151 | ++ )); |
| 152 | + |
| 153 | + return new Response($content); |
| 154 | + } |
| 155 | +diff --git a/views/attendees.twig b/views/attendees.twig |
| 156 | +new file mode 100644 |
| 157 | +index 0000000..106ec00 |
| 158 | +--- /dev/null |
| 159 | ++++ b/views/attendees.twig |
| 160 | +@@ -0,0 +1,13 @@ |
| 161 | ++<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" /> |
| 162 | ++ |
| 163 | ++<h1>PHP Camp Attendees</h1> |
| 164 | ++<table class="table" style="width: 300px;"> |
| 165 | ++ {% for camper in campers %} |
| 166 | ++ <tr> |
| 167 | ++ <td style="font-size: 24px;"> |
| 168 | ++ {{ camper.attendee }} |
| 169 | ++ </td> |
| 170 | ++ <td><img src="{{ camper.avatar_url }}" height="120" /></td> |
| 171 | ++ </tr> |
| 172 | ++ {% endfor %} |
| 173 | ++</table> |
| 174 | +diff --git a/views/homepage.twig b/views/homepage.twig |
| 175 | +new file mode 100644 |
| 176 | +index 0000000..fbe632e |
| 177 | +--- /dev/null |
| 178 | ++++ b/views/homepage.twig |
| 179 | +@@ -0,0 +1,7 @@ |
| 180 | ++<h1>PHP Camp!</h1> |
| 181 | ++ |
| 182 | ++<a href="/attendees">See the attendees</a> |
| 183 | ++ |
| 184 | ++{% if name %} |
| 185 | ++ <p>Oh, and hello {{ name }}!</p> |
| 186 | ++{% endif %} |
0 commit comments