Skip to content

Fixed code examples #1531

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 43 commits into from
Jul 14, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c354c00
Fixed code examples in book/controller
wouterj Jul 5, 2012
8b3605a
Fixed code examples in book/doctrine
wouterj Jul 5, 2012
e069e66
Fixed code examples in book/forms
wouterj Jul 5, 2012
4c61469
Fixed code examples in book/from_flat_to_symfony
wouterj Jul 5, 2012
67991a8
Fixed code examples in book/http_cache
wouterj Jul 5, 2012
0f401b8
Fixed code examples in book/http_fundamentals
wouterj Jul 5, 2012
29c0a1f
Fixed code examples in book/internals
wouterj Jul 5, 2012
08af3c9
Fixed code examples in book/propel
wouterj Jul 5, 2012
4496d51
Fixed code examples in book/routing
wouterj Jul 5, 2012
7f8f90a
Fixed code examples in book/security
wouterj Jul 5, 2012
499a3d1
Fixed code examples in book/service_container
wouterj Jul 5, 2012
4ddc58a
Fixed code examples in book/templating
wouterj Jul 5, 2012
d5c7880
Refixed some code examples in book/controller and book/routing
wouterj Jul 5, 2012
05fb56d
Fixed code examples in book/testing
wouterj Jul 5, 2012
59c1e41
Fixed code examples in book/translation
wouterj Jul 5, 2012
1cfd349
Fixed code examples in book/validation
wouterj Jul 5, 2012
be95682
Fixed code examples in components/di
wouterj Jul 5, 2012
df3f59e
Fixed code examples in components/event_dispatcher
wouterj Jul 5, 2012
1d05e44
Fixed code examples in components/http_foundation
wouterj Jul 5, 2012
6ec0e9c
Fixed code examples in components/class_loader
wouterj Jul 5, 2012
4c773e1
Fixed code examples in components/console.rst
wouterj Jul 5, 2012
7998afa
Fixed code examples in components/dom_crawler
wouterj Jul 5, 2012
5b3ca6d
Fixed code examples in components/finder.rst
wouterj Jul 5, 2012
7849678
Fixed code examples in components/routing
wouterj Jul 5, 2012
bc95ecc
Fixed code examples in components/templating
wouterj Jul 5, 2012
c0e8a9a
Fixed code examples in cookbook/assetic
wouterj Jul 5, 2012
7b4fd66
Fixed code examples in cookbook/bundles
wouterj Jul 6, 2012
28d11a9
Fixed code examples in cookbook/configuration
wouterj Jul 6, 2012
1964d8e
Fixed code examples in cookbook/doctrine
wouterj Jul 6, 2012
d184401
Fixed code examples in cookbook/email
wouterj Jul 6, 2012
b80186e
Fixed code examples in cookbook/event_dispatcher
wouterj Jul 6, 2012
586bd1f
Fixed some naming conventions in cookbook/bundles
wouterj Jul 6, 2012
3fc64a0
Fixed code examples in cookbook/form
wouterj Jul 6, 2012
069791d
Fixed code examples in cookbook/logging
wouterj Jul 6, 2012
35e43cd
Fixed code exampels in cookbook/routing
wouterj Jul 6, 2012
1f52ad4
Fixed code examples in cookbook/security
wouterj Jul 6, 2012
c9bb545
Fixed code examples in cookbook/service_container
wouterj Jul 6, 2012
a4c1e2d
Fixed code examples in cookbook/templating
wouterj Jul 6, 2012
1d0fe96
Fixed code examples in cookbook/testing
wouterj Jul 6, 2012
46fb58b
Fixed code examples in cookbook/validation
wouterj Jul 6, 2012
594d97a
Fixed code examples in cookbook/web_services
wouterj Jul 6, 2012
66646ce
Fixed code examples in cookbook/symfony1
wouterj Jul 6, 2012
917be05
Fixed code examples in quick_tour
wouterj Jul 6, 2012
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
19 changes: 10 additions & 9 deletions book/controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ a controller object. Controllers are also called *actions*.
:linenos:

// src/Acme/HelloBundle/Controller/HelloController.php

namespace Acme\HelloBundle\Controller;

use Symfony\Component\HttpFoundation\Response;

class HelloController
Expand Down Expand Up @@ -208,8 +208,8 @@ passed to that method:

<?php
// src/Acme/HelloBundle/Controller/HelloController.php

namespace Acme\HelloBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class HelloController extends Controller
Expand Down Expand Up @@ -276,7 +276,7 @@ the following guidelines in mind while you develop.

public function indexAction($last_name, $color, $first_name)
{
// ..
// ...
}

* **Each required controller argument must match up with a routing parameter**
Expand All @@ -286,15 +286,15 @@ the following guidelines in mind while you develop.

public function indexAction($first_name, $last_name, $color, $foo)
{
// ..
// ...
}

Making the argument optional, however, is perfectly ok. The following
example would not throw an exception::

public function indexAction($first_name, $last_name, $color, $foo = 'bar')
{
// ..
// ...
}

* **Not all routing parameters need to be arguments on your controller**
Expand All @@ -304,7 +304,7 @@ the following guidelines in mind while you develop.

public function indexAction($first_name, $color)
{
// ..
// ...
}

.. tip::
Expand Down Expand Up @@ -349,8 +349,8 @@ Add the ``use`` statement atop the ``Controller`` class and then modify the
.. code-block:: php

// src/Acme/HelloBundle/Controller/HelloController.php

namespace Acme\HelloBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;

Expand Down Expand Up @@ -448,7 +448,7 @@ object that's returned from that controller::
'color' => 'green'
));

// further modify the response or return it directly
// ... further modify the response or return it directly

return $response;
}
Expand Down Expand Up @@ -570,7 +570,8 @@ If you're extending the base controller class, do the following::

public function indexAction()
{
$product = // retrieve the object from database
// retrieve the object from database
$product = ...;
if (!$product) {
throw $this->createNotFoundException('The product does not exist');
}
Expand Down
17 changes: 11 additions & 6 deletions book/doctrine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ information. By convention, this information is usually configured in an

.. code-block:: ini

;app/config/parameters.ini
; app/config/parameters.ini
[parameters]
database_driver = pdo_mysql
database_host = localhost
Expand All @@ -64,6 +64,7 @@ information. By convention, this information is usually configured in an

.. code-block:: yaml

# app/config/config.yml
doctrine:
dbal:
driver: %database_driver%
Expand Down Expand Up @@ -366,9 +367,10 @@ of the bundle:
:linenos:

// src/Acme/StoreBundle/Controller/DefaultController.php

// ...
use Acme\StoreBundle\Entity\Product;
use Symfony\Component\HttpFoundation\Response;
// ...

public function createAction()
{
Expand Down Expand Up @@ -444,7 +446,7 @@ on its ``id`` value::
throw $this->createNotFoundException('No product found for id '.$id);
}

// do something, like pass the $product object into a template
// ... do something, like pass the $product object into a template
}

When you query for a particular type of object, you always use what's known
Expand Down Expand Up @@ -605,7 +607,7 @@ for just one object, you can use the ``getSingleResult()`` method instead::
returned (if you're querying on something that could feasibly return
more than one result)::

$query = $em->createQuery('SELECT ....')
$query = $em->createQuery('SELECT ...')
->setMaxResults(1);

try {
Expand Down Expand Up @@ -710,6 +712,7 @@ To do this, add the name of the repository class to your mapping definition.
.. code-block:: xml

<!-- src/Acme/StoreBundle/Resources/config/doctrine/Product.orm.xml -->

<!-- ... -->
<doctrine-mapping>

Expand Down Expand Up @@ -792,6 +795,7 @@ To relate the ``Category`` and ``Product`` entities, start by creating a
.. code-block:: php-annotations

// src/Acme/StoreBundle/Entity/Category.php

// ...
use Doctrine\Common\Collections\ArrayCollection;

Expand Down Expand Up @@ -852,6 +856,7 @@ object, you'll want to add a ``$category`` property to the ``Product`` class:
.. code-block:: php-annotations

// src/Acme/StoreBundle/Entity/Product.php

// ...

class Product
Expand Down Expand Up @@ -928,10 +933,10 @@ Saving Related Entities
Now, let's see the code in action. Imagine you're inside a controller::

// ...

use Acme\StoreBundle\Entity\Category;
use Acme\StoreBundle\Entity\Product;
use Symfony\Component\HttpFoundation\Response;
// ...

class DefaultController extends Controller
{
Expand Down Expand Up @@ -1058,7 +1063,6 @@ can avoid the second query by issuing a join in the original query. Add the
following method to the ``ProductRepository`` class::

// src/Acme/StoreBundle/Repository/ProductRepository.php

public function findOneByIdJoinedToCategory($id)
{
$query = $this->getEntityManager()
Expand Down Expand Up @@ -1162,6 +1166,7 @@ the current date, only when the entity is first persisted (i.e. inserted):
.. code-block:: xml

<!-- src/Acme/StoreBundle/Resources/config/doctrine/Product.orm.xml -->

<!-- ... -->
<doctrine-mapping>

Expand Down
22 changes: 3 additions & 19 deletions book/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ helper functions:
.. code-block:: html+jinja

{# src/Acme/TaskBundle/Resources/views/Default/new.html.twig #}

<form action="{{ path('task_new') }}" method="post" {{ form_enctype(form) }}>
{{ form_widget(form) }}

Expand All @@ -157,7 +156,6 @@ helper functions:
.. code-block:: html+php

<!-- src/Acme/TaskBundle/Resources/views/Default/new.html.php -->

<form action="<?php echo $view['router']->generate('task_new') ?>" method="post" <?php echo $view['form']->enctype($form) ?> >
<?php echo $view['form']->widget($form) ?>

Expand Down Expand Up @@ -386,8 +384,7 @@ you'll need to specify which validation group(s) your form should use::

$form = $this->createFormBuilder($users, array(
'validation_groups' => array('registration'),
))->add(...)
;
))->add(...);

If you're creating :ref:`form classes<book-form-creating-form-classes>` (a
good practice), then you'll need to add the following to the ``getDefaultOptions()``
Expand Down Expand Up @@ -558,7 +555,6 @@ of code. Of course, you'll usually need much more flexibility when rendering:
.. code-block:: html+jinja

{# src/Acme/TaskBundle/Resources/views/Default/new.html.twig #}

<form action="{{ path('task_new') }}" method="post" {{ form_enctype(form) }}>
{{ form_errors(form) }}

Expand All @@ -572,8 +568,7 @@ of code. Of course, you'll usually need much more flexibility when rendering:

.. code-block:: html+php

<!-- // src/Acme/TaskBundle/Resources/views/Default/newAction.html.php -->

<!-- src/Acme/TaskBundle/Resources/views/Default/newAction.html.php -->
<form action="<?php echo $view['router']->generate('task_new') ?>" method="post" <?php echo $view['form']->enctype($form) ?>>
<?php echo $view['form']->errors($form) ?>

Expand Down Expand Up @@ -754,7 +749,6 @@ that will house the logic for building the task form:
.. code-block:: php

// src/Acme/TaskBundle/Form/Type/TaskType.php

namespace Acme\TaskBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
Expand Down Expand Up @@ -787,7 +781,7 @@ form "type"). It can be used to quickly build a form object in the controller:

public function newAction()
{
$task = // ...
$task = ...;
$form = $this->createForm(new TaskType(), $task);

// ...
Expand Down Expand Up @@ -1052,7 +1046,6 @@ do this, create a new template file that will store the new markup:
.. code-block:: html+jinja

{# src/Acme/TaskBundle/Resources/views/Form/fields.html.twig #}

{% block field_row %}
{% spaceless %}
<div class="form_row">
Expand All @@ -1066,7 +1059,6 @@ do this, create a new template file that will store the new markup:
.. code-block:: html+php

<!-- src/Acme/TaskBundle/Resources/views/Form/field_row.html.php -->

<div class="form_row">
<?php echo $view['form']->label($form, $label) ?>
<?php echo $view['form']->errors($form) ?>
Expand All @@ -1083,7 +1075,6 @@ renders the form:
.. code-block:: html+jinja

{# src/Acme/TaskBundle/Resources/views/Default/new.html.twig #}

{% form_theme form 'AcmeTaskBundle:Form:fields.html.twig' %}

{% form_theme form 'AcmeTaskBundle:Form:fields.html.twig' 'AcmeTaskBundle:Form:fields2.html.twig' %}
Expand All @@ -1093,7 +1084,6 @@ renders the form:
.. code-block:: html+php

<!-- src/Acme/TaskBundle/Resources/views/Default/new.html.php -->

<?php $view['form']->setTheme($form, array('AcmeTaskBundle:Form')) ?>

<?php $view['form']->setTheme($form, array('AcmeTaskBundle:Form', 'AcmeTaskBundle:Form')) ?>
Expand Down Expand Up @@ -1219,7 +1209,6 @@ file:
.. code-block:: yaml

# app/config/config.yml

twig:
form:
resources:
Expand All @@ -1229,7 +1218,6 @@ file:
.. code-block:: xml

<!-- app/config/config.xml -->

<twig:config ...>
<twig:form>
<resource>AcmeTaskBundle:Form:fields.html.twig</resource>
Expand All @@ -1240,7 +1228,6 @@ file:
.. code-block:: php

// app/config/config.php

$container->loadFromExtension('twig', array(
'form' => array('resources' => array(
'AcmeTaskBundle:Form:fields.html.twig',
Expand Down Expand Up @@ -1297,7 +1284,6 @@ file:
.. code-block:: yaml

# app/config/config.yml

framework:
templating:
form:
Expand All @@ -1309,7 +1295,6 @@ file:
.. code-block:: xml

<!-- app/config/config.xml -->

<framework:config ...>
<framework:templating>
<framework:form>
Expand All @@ -1322,7 +1307,6 @@ file:
.. code-block:: php

// app/config/config.php

$container->loadFromExtension('framework', array(
'templating' => array('form' =>
array('resources' => array(
Expand Down
Loading