@@ -420,34 +420,29 @@ Why should you have to reinvent solutions to all these routine problems?
420
420
Add a Touch of Symfony2
421
421
~~~~~~~~~~~~~~~~~~~~~~~
422
422
423
- Symfony2 to the rescue. Before actually using Symfony2, you need to make
424
- sure PHP knows how to find the Symfony2 classes. This is accomplished via
425
- an autoloader that Symfony provides. An autoloader is a tool that makes it
426
- possible to start using PHP classes without explicitly including the file
427
- containing the class.
423
+ Symfony2 to the rescue. Before actually using Symfony2, you need to download
424
+ it. This can be done by using composer, which takes care of downloading the
425
+ correct version and all it's dependencies and provides an autoloader. An
426
+ autoloader is a tool that makes it possible to start using PHP classes
427
+ without explicitly including the file containing the class.
428
428
429
- First, `download Symfony `_ and place it into a ``vendor/symfony/symfony/ `` directory.
430
- Next, create an ``app/bootstrap.php `` file. Use it to ``require `` the two
431
- files in the application and to configure the autoloader:
429
+ In your root directory, create a ``composer.json `` file with the following
430
+ content:
432
431
433
- .. code-block :: html+php
434
-
435
- <?php
436
- // bootstrap.php
437
- require_once 'model.php';
438
- require_once 'controllers.php';
439
- require_once 'vendor/symfony/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
432
+ .. code-block :: json
440
433
441
- $loader = new Symfony\C omponent\C lassLoader\U niversalClassLoader();
442
- $loader->registerNamespaces(array(
443
- 'Symfony' => __DIR__.'/../vendor/symfony/symfony/src',
444
- ));
445
-
446
- $loader->register();
447
-
448
- This tells the autoloader where the ``Symfony `` classes are. With this, you
449
- can start using Symfony classes without using the ``require `` statement for
450
- the files that contain them.
434
+ {
435
+ "require" : {
436
+ "symfony/symfony" : " 2.1.*"
437
+ },
438
+ "autoload" : {
439
+ "files" : [" model.php" ," controller.php" ]
440
+ }
441
+ }
442
+
443
+ After installing your dependencies, composer has generated ``vendor/autoload.php ``,
444
+ which takes care to include all files from the symfony framework as well as
445
+ the files mentioned in the autoload section of your composer.json.
451
446
452
447
Core to Symfony's philosophy is the idea that an application's main job is
453
448
to interpret each request and return a response. To this end, Symfony2 provides
@@ -460,7 +455,7 @@ the HTTP response being returned. Use them to improve the blog:
460
455
461
456
<?php
462
457
// index.php
463
- require_once 'app /bootstrap.php';
458
+ require_once 'vendor /bootstrap.php';
464
459
465
460
use Symfony\C omponent\H ttpFoundation\R equest;
466
461
use Symfony\C omponent\H ttpFoundation\R esponse;
0 commit comments