@@ -55,13 +55,13 @@ Next, create an ``index.php`` file that defines the kernel class and executes it
5555 {
5656 // kernel is a service that points to this class
5757 // optional 3rd argument is the route name
58- $routes->add('/random/{limit}', 'kernel :randomNumber');
58+ $routes->add('/random/{limit}', 'Kernel: :randomNumber');
5959 }
6060
6161 public function randomNumber($limit)
6262 {
6363 return new JsonResponse(array(
64- 'number' =>rand (0, $limit)
64+ 'number' =>random_int (0, $limit),
6565 ));
6666 }
6767 }
@@ -136,11 +136,6 @@ hold the kernel. Now it looks like this::
136136 use Symfony\Component\DependencyInjection\ContainerBuilder;
137137 use Symfony\Component\HttpKernel\Kernel as BaseKernel;
138138 use Symfony\Component\Routing\RouteCollectionBuilder;
139- use Doctrine\Common\Annotations\AnnotationRegistry;
140-
141- $loader = require __DIR__.'/../vendor/autoload.php';
142- // auto-load annotations
143- AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
144139
145140 class Kernel extends BaseKernel
146141 {
@@ -149,8 +144,8 @@ hold the kernel. Now it looks like this::
149144 public function registerBundles()
150145 {
151146 $bundles = array(
152- new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
153- new Symfony\Bundle\TwigBundle\TwigBundle(),
147+ new\ Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
148+ new\ Symfony\Bundle\TwigBundle\TwigBundle(),
154149 );
155150
156151 if ($this->getEnvironment() == 'dev') {
@@ -162,7 +157,7 @@ hold the kernel. Now it looks like this::
162157
163158 protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
164159 {
165- $loader->load(__DIR__.'/config/framework.yaml');
160+ $loader->load(__DIR__.'/../ config/framework.yaml');
166161
167162 // configure WebProfilerBundle only if the bundle is enabled
168163 if (isset($this->bundles['WebProfilerBundle'])) {
@@ -198,6 +193,12 @@ hold the kernel. Now it looks like this::
198193 }
199194 }
200195
196+ Before you continue, run this command to add support for the new dependencies:
197+
198+ ..code-block ::terminal
199+
200+ composer require symfony/yaml symfony/twig-bundle symfony/web-profiler-bundle doctrine/annotations
201+
201202 Unlike the previous kernel, this loads an external ``config/framework.yaml `` file,
202203because the configuration started to get bigger:
203204
@@ -208,8 +209,6 @@ because the configuration started to get bigger:
208209# config/framework.yaml
209210framework :
210211secret :S0ME_SECRET
211- templating :
212- engines :['twig']
213212profiler :{ only_exceptions: false }
214213
215214 ..code-block ::xml
@@ -223,9 +222,6 @@ because the configuration started to get bigger:
223222 http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
224223
225224 <framework : config secret =" S0ME_SECRET" >
226- <framework : templating >
227- <framework : engine >twig</framework : engine >
228- </framework : templating >
229225 <framework : profiler only-exceptions =" false" />
230226 </framework : config >
231227 </container >
@@ -235,9 +231,6 @@ because the configuration started to get bigger:
235231 // config/framework.php
236232 $container->loadFromExtension('framework', array(
237233 'secret' => 'S0ME_SECRET',
238- 'templating' => array(
239- 'engines' => array('twig'),
240- ),
241234 'profiler' => array(
242235 'only_exceptions' => false,
243236 ),
@@ -259,21 +252,20 @@ has one file in it::
259252 */
260253 public function randomNumber($limit)
261254 {
262- $number =rand (0, $limit);
255+ $number =random_int (0, $limit);
263256
264257 return $this->render('micro/random.html.twig', array(
265- 'number' => $number
258+ 'number' => $number,
266259 ));
267260 }
268261 }
269262
270- Template files should live in the ``Resources/views/ `` directory of whatever directory
271- your *kernel * lives in. Since ``Kernel `` lives in ``src/ ``, this template lives
272- at ``src/Resources/views/micro/random.html.twig ``:
263+ Template files should live in the ``templates/ `` directory at the root of your project.
264+ This template lives at ``templates/micro/random.html.twig ``:
273265
274266..code-block ::html+twig
275267
276- <!--src/Resources/views /micro/random.html.twig -->
268+ <!--templates /micro/random.html.twig -->
277269 <!DOCTYPE html>
278270 <html>
279271 <head>
@@ -289,9 +281,13 @@ Finally, you need a front controller to boot and run the application. Create a
289281
290282 // public/index.php
291283
284+ use App\Kernel;
285+ use Doctrine\Common\Annotations\AnnotationRegistry;
292286 use Symfony\Component\HttpFoundation\Request;
293287
294- require __DIR__.'/../src/Kernel.php';
288+ $loader = require __DIR__.'/../vendor/autoload.php';
289+ // auto-load annotations
290+ AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
295291
296292 $kernel = new Kernel('dev', true);
297293 $request = Request::createFromGlobals();
@@ -311,13 +307,12 @@ this:
311307 ├─ public/
312308 | └─ index.php
313309 ├─ src/
314- | ├─ Kernel.php
315310 | ├─ Controller
316311 | | └─ MicroController.php
317- │ └─Resources
318- | └─ views
319- | └─ micro
320- | └─ random.html.twig
312+ | └─Kernel.php
313+ ├─ templates/
314+ | └─ micro/
315+ | └─ random.html.twig
321316 ├─ var/
322317 | ├─ cache/
323318 │ └─ log/
@@ -331,7 +326,7 @@ As before you can use PHP built-in server:
331326..code-block ::terminal
332327
333328 cd public/
334- $ php -S localhost:8000
329+ $ php -S localhost:8000 -t public/
335330
336331 Then see webpage in browser:
337332