@@ -420,34 +420,36 @@ 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 its 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
432
+ .. code-block :: json
434
433
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';
434
+ {
435
+ "require" : {
436
+ "symfony/symfony" : " 2.1.*"
437
+ },
438
+ "autoload" : {
439
+ "files" : [" model.php" ," controller.php" ]
440
+ }
441
+ }
442
+
443
+ Next, `download Composer `_ and then run the following command, which will download Symfony
444
+ into a vendor/ directory:
440
445
441
- $loader = new Symfony\C omponent\C lassLoader\U niversalClassLoader();
442
- $loader->registerNamespaces(array(
443
- 'Symfony' => __DIR__.'/../vendor/symfony/symfony/src',
444
- ));
446
+ .. code-block :: bash
445
447
446
- $loader->register();
448
+ $ php composer.phar install
447
449
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 .
450
+ Beside downloading your dependencies, Composer generates a `` vendor/autoload.php `` file,
451
+ which takes care of autoloading for all the files in the Symfony Framework as well as
452
+ the files mentioned in the autoload section of your ` composer.json ` .
451
453
452
454
Core to Symfony's philosophy is the idea that an application's main job is
453
455
to interpret each request and return a response. To this end, Symfony2 provides
@@ -460,7 +462,7 @@ the HTTP response being returned. Use them to improve the blog:
460
462
461
463
<?php
462
464
// index.php
463
- require_once 'app /bootstrap.php';
465
+ require_once 'vendor /bootstrap.php';
464
466
465
467
use Symfony\C omponent\H ttpFoundation\R equest;
466
468
use Symfony\C omponent\H ttpFoundation\R esponse;
@@ -752,7 +754,7 @@ Learn more from the Cookbook
752
754
* :doc: `/cookbook/controller/service `
753
755
754
756
.. _`Doctrine` : http://www.doctrine-project.org
755
- .. _`download Symfony ` : http://symfony.com /download
757
+ .. _`download Composer ` : http://getcomposer.org /download/
756
758
.. _`Routing` : https://github.com/symfony/Routing
757
759
.. _`Templating` : https://github.com/symfony/Templating
758
760
.. _`KnpBundles.com` : http://knpbundles.com/
0 commit comments