Skip to content

Changing description of symfony installation to composer #1993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 16, 2012
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 21 additions & 26 deletions book/from_flat_php_to_symfony2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -420,34 +420,29 @@ Why should you have to reinvent solutions to all these routine problems?
Add a Touch of Symfony2
~~~~~~~~~~~~~~~~~~~~~~~

Symfony2 to the rescue. Before actually using Symfony2, you need to make
sure PHP knows how to find the Symfony2 classes. This is accomplished via
an autoloader that Symfony provides. An autoloader is a tool that makes it
possible to start using PHP classes without explicitly including the file
containing the class.
Symfony2 to the rescue. Before actually using Symfony2, you need to download
it. This can be done by using composer, which takes care of downloading the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Composer - capital C

correct version and all it's dependencies and provides an autoloader. An
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its - no apostrophe :)

autoloader is a tool that makes it possible to start using PHP classes
without explicitly including the file containing the class.

First, `download Symfony`_ and place it into a ``vendor/symfony/symfony/`` directory.
Next, create an ``app/bootstrap.php`` file. Use it to ``require`` the two
files in the application and to configure the autoloader:
In your root directory, create a ``composer.json`` file with the following
content:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this method, the recommend way to start a symfony project is:

$ php composer.phar create-project symfony/framework-standard-edition 2.1.x path/to/project

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the impression that in this part of the docs, only the symfony core is used, not the full-stack framework?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's right - we're actually only need a few specific components, but of course we're not teaching Composer or those finer details, so I like how you've bright in symfony/symfony via Composer.


.. code-block:: html+php

<?php
// bootstrap.php
require_once 'model.php';
require_once 'controllers.php';
require_once 'vendor/symfony/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
.. code-block:: json

$loader = new Symfony\Component\ClassLoader\UniversalClassLoader();
$loader->registerNamespaces(array(
'Symfony' => __DIR__.'/../vendor/symfony/symfony/src',
));

$loader->register();

This tells the autoloader where the ``Symfony`` classes are. With this, you
can start using Symfony classes without using the ``require`` statement for
the files that contain them.
{
"require": {
"symfony/symfony": "2.1.*"
},
"autoload": {
"files": ["model.php","controller.php"]
}
}

After installing your dependencies, composer has generated ``vendor/autoload.php``,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

capitalize the C here as well

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And yes, I see what you're saying now about how much of the Composer details to actually have here. I would say something like:

Next, download composer_ and then run the following command, which will download Symfony
into a vendor/ directory:

.. code-block:: bash

   $ php composer.phar install

This command also generates a vendor/autoload.php file, which takes care of autoloading for
all the files in the Symfony Framework as well as the files mentioned...

which takes care to include all files from the symfony framework as well as
the files mentioned in the autoload section of your composer.json.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap composer.json in the double ticks:

``composer.json``


Core to Symfony's philosophy is the idea that an application's main job is
to interpret each request and return a response. To this end, Symfony2 provides
Expand All @@ -460,7 +455,7 @@ the HTTP response being returned. Use them to improve the blog:

<?php
// index.php
require_once 'app/bootstrap.php';
require_once 'vendor/bootstrap.php';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just starting w/symfony. Right now at this part in the book. Got set with composer as shown. No vendor/bootstrap.php was created, only vendor/autoload.php. I made a bootstrap from https://github.com/ruian/RuianSeoBundle/blob/master/vendor/bootstrap.php

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpmsk you are right, there is no vendor/bootstrap.php, we mean vendor/autoload.php here. I submited a fix for this: #2157

BTW: You shouldn't use the examples here if you are going to use the full Symfony framework. This article just shows you what the advantages of this framework are.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks. Your reply means a lot. On first look symfony looks friendly
and powerful but also intimidating and difficult to know how to approach it.
I think I have a feel for what the page at
http://symfony.com/doc/current/book/from_flat_php_to_symfony2.html is
intended for. It's a really good way to explain things - simple and coming
from plain "flat" basic php with no dependant code involved.

On Sat, Jan 19, 2013 at 1:02 AM, Wouter J notifications@github.com wrote:

In book/from_flat_php_to_symfony2.rst:

@@ -460,7 +462,7 @@ the HTTP response being returned. Use them to improve the blog:

 <?php
 // index.php
  • require_once 'app/bootstrap.php';
  • require_once 'vendor/bootstrap.php';

@rpmsk https://github.com/rpmsk you are right, there is no
vendor/bootstrap.php, we mean vendor/autoload.php here. I submited a fix
for this: #2157 #2157

BTW: You shouldn't use the examples here if you are going to use the full
Symfony framework. This article just shows you what the advantages of this
framework are.


Reply to this email directly or view it on GitHubhttps://github.com//pull/1993/files#r2705072.


use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down