Skip to content

Commit

Permalink
Merge branch '2.7'
Browse files Browse the repository at this point in the history
* 2.7: (103 commits)
  Backporting some stuff from 2.7, that I think must have gotten merged only there by accident
  [#5064] Minor language tweaks
  Fixing bad merge conflict (forgot to save!)
  Remove unnecessary component reference
  Correct RegisterListenersPass namespace
  Fix service id
  Switched the first example to a static constructor method
  added some more components for Tobion as a merger
  Fixed variable name in : Reference -> validation constraints -> count -> basic usage -> PHP
  [#5036] Typo fix (probably mine originally) caught by xabbuh
  reword to serves
  Adding a link to define "lts"
  Better wording
  Minor improvement for symfony-installer with LTS
  Updating for new security service names in 2.6
  [#5033] Tweaking variable name to "match" the service id
  [#5017] Minor language tweaks
  [#5015] Updating the security service name for 2.6 - thanks to Cordoval
  [#5015] Very small tweak
  [#5011] Adding one more fix I missed
  ...
  • Loading branch information
weaverryan committed Mar 14, 2015
2 parents feb621b + 1fccbf6 commit f24c84f
Show file tree
Hide file tree
Showing 55 changed files with 756 additions and 245 deletions.
46 changes: 30 additions & 16 deletions book/controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -429,35 +429,47 @@ A great way to see the core functionality in action is to look in the
Redirecting
~~~~~~~~~~~

If you want to redirect the user to another page, use the
:method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::redirect`
method::
If you want to redirect the user to another page, use the ``redirectToRoute()`` method::

public function indexAction()
{
return $this->redirect($this->generateUrl('homepage'));
return $this->redirectToRoute('homepage');

// redirectToRoute is equivalent to using redirect() and generateUrl() together:
// return $this->redirect($this->generateUrl('homepage'), 301);
}

The ``generateUrl()`` method is just a helper function that generates the URL
for a given route. For more information, see the :doc:`Routing </book/routing>`
chapter.
.. versionadded:: 2.6
The ``redirectToRoute()`` method was added in Symfony 2.6. Previously (and still now), you
could use ``redirect()`` and ``generateUrl()`` together for this (see the example above).

Or, if you want to redirect externally, just use ``redirect()`` and pass it the URL::

public function indexAction()
{
return $this->redirect('http://symfony.com/doc');
}

By default, the ``redirect()`` method performs a 302 (temporary) redirect. To
By default, the ``redirectToRoute()`` method performs a 302 (temporary) redirect. To
perform a 301 (permanent) redirect, modify the second argument::

public function indexAction()
{
return $this->redirect($this->generateUrl('homepage'), 301);
return $this->redirectToRoute('homepage', array(), 301);
}

.. tip::

The ``redirect()`` method is simply a shortcut that creates a ``Response``
object that specializes in redirecting the user. It's equivalent to::
The ``redirectToRoute()`` method is simply a shortcut that creates a
``Response`` object that specializes in redirecting the user. It's
equivalent to::

use Symfony\Component\HttpFoundation\RedirectResponse;

return new RedirectResponse($this->generateUrl('homepage'));
public function indexAction()
{
return new RedirectResponse($this->generateUrl('homepage'));
}

.. index::
single: Controller; Rendering templates
Expand Down Expand Up @@ -623,12 +635,14 @@ For example, imagine you're processing a form submit::
if ($form->isValid()) {
// do some sort of processing

$request->getSession()->getFlashBag()->add(
$this->addFlash(
'notice',
'Your changes were saved!'
);

return $this->redirect($this->generateUrl(...));
// $this->addFlash is equivalent to $this->get('session')->getFlashBag()->add

return $this->redirectToRoute(...);
}

return $this->render(...);
Expand All @@ -638,8 +652,8 @@ After processing the request, the controller sets a ``notice`` flash message
in the session and then redirects. The name (``notice``) isn't significant -
it's just something you invent and reference next.

In the template of the next page (or even better, in your base layout template),
the following code will render the ``notice`` message:
In the template of the next action, the following code could be used to render
the ``notice`` message:

.. configuration-block::

Expand Down
4 changes: 3 additions & 1 deletion book/doctrine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ you have a route that maps a product id to an update action in a controller::
$product->setName('New product name!');
$em->flush();

return $this->redirect($this->generateUrl('homepage'));
return $this->redirectToRoute('homepage');
}

Updating an object involves just three steps:
Expand Down Expand Up @@ -778,6 +778,8 @@ entities (the topic of :ref:`relations <book-doctrine-relations>` will be
covered later), group, etc. For more information, see the official
`Doctrine Query Language`_ documentation.

.. _book-doctrine-custom-repository-classes:

Custom Repository Classes
~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
6 changes: 3 additions & 3 deletions book/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ controller::
if ($form->isValid()) {
// perform some action, such as saving the task to the database

return $this->redirect($this->generateUrl('task_success'));
return $this->redirectToRoute('task_success');
}

// ...
Expand Down Expand Up @@ -319,7 +319,7 @@ querying if the "Save and add" button was clicked::
? 'task_new'
: 'task_success';

return $this->redirect($this->generateUrl($nextAction));
return $this->redirectToRoute($nextAction);
}

.. index::
Expand Down Expand Up @@ -1237,7 +1237,7 @@ it after a form submission can be done when the form is valid::
$em->persist($task);
$em->flush();

return $this->redirect($this->generateUrl('task_success'));
return $this->redirectToRoute('task_success');
}

If, for some reason, you don't have access to your original ``$task`` object,
Expand Down
6 changes: 6 additions & 0 deletions book/http_cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ kernel::
The caching kernel will immediately act as a reverse proxy - caching responses
from your application and returning them to the client.

.. caution::

If you're using the :ref:`framework.http_method_override <configuration-framework-http_method_override>`
option to read the HTTP method from a ``_method`` parameter, see the
above link for a tweak you need to make.

.. tip::

The cache kernel has a special ``getLog()`` method that returns a string
Expand Down
11 changes: 11 additions & 0 deletions book/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ number as the second argument of the ``new`` command:
# Windows
c:\projects\> php symfony.phar new my_project_name 2.3.23
If you want your project to be based on the latest :ref:`Symfony LTS version <releases-lts>`,
pass ``lts`` as the second argument of the ``new`` command:

.. code-block:: bash
# Linux, Mac OS X
$ symfony new my_project_name lts
# Windows
c:\projects\> php symfony.phar new my_project_name lts
Read the :doc:`Symfony Release process </contributing/community/releases>`
to better understand why there are several Symfony versions and which one
to use for your projects.
Expand Down
6 changes: 4 additions & 2 deletions book/performance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ Use a Byte Code Cache (e.g. APC)
One of the best (and easiest) things that you should do to improve your performance
is to use a "byte code cache". The idea of a byte code cache is to remove
the need to constantly recompile the PHP source code. There are a number of
`byte code caches`_ available, some of which are open source. The most widely
used byte code cache is probably `APC`_
`byte code caches`_ available, some of which are open source. As of PHP 5.5,
PHP comes with `OPcache`_ built-in. For older versions, the most widely used
byte code cache is probably `APC`_

Using a byte code cache really has no downside, and Symfony has been architected
to perform really well in this type of environment.
Expand Down Expand Up @@ -139,6 +140,7 @@ feature is disabled in the byte code cache (e.g. ``apc.stat=0`` in APC), there
is no longer a reason to use a bootstrap file.

.. _`byte code caches`: http://en.wikipedia.org/wiki/List_of_PHP_accelerators
.. _`OPcache`: http://php.net/manual/en/book.opcache.php
.. _`APC`: http://php.net/manual/en/book.apc.php
.. _`autoload.php`: https://github.com/symfony/symfony-standard/blob/master/app/autoload.php
.. _`bootstrap file`: https://github.com/sensio/SensioDistributionBundle/blob/master/Composer/ScriptHandler.php
2 changes: 1 addition & 1 deletion book/propel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ have a route that maps a product id to an update action in a controller::
$product->setName('New product name!');
$product->save();

return $this->redirect($this->generateUrl('homepage'));
return $this->redirectToRoute('homepage');
}
}

Expand Down
2 changes: 1 addition & 1 deletion book/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The route is simple:
class BlogController extends Controller
{
/**
* @Route("/blog/{slug}")
* @Route("/blog/{slug}", name="blog_show")
*/
public function showAction($slug)
{
Expand Down
25 changes: 17 additions & 8 deletions book/security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -813,20 +813,29 @@ You can easily deny access from inside a controller::

public function helloAction($name)
{
if (false === $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) {
throw $this->createAccessDeniedException();
}
// The second parameter is used to specify on what object the role is tested.
$this->denyAccessUnlessGranted('ROLE_ADMIN', null, 'Unable to access this page!');

// Old way :
// if (false === $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) {
// throw $this->createAccessDeniedException('Unable to access this page!');
// }

// ...
}

.. versionadded:: 2.6
The ``security.authorization_checker`` service was introduced in Symfony 2.6. Prior
to Symfony 2.6, you had to use the ``isGranted()`` method of the ``security.context`` service.
The ``denyAccessUnlessGranted()`` method was introduced in Symfony 2.6. Previously (and
still now), you could check access directly and throw the ``AccessDeniedException`` as shown
in the example above).

.. versionadded:: 2.6
The ``security.authorization_checker`` service was introduced in Symfony 2.6. Prior
to Symfony 2.6, you had to use the ``isGranted()`` method of the ``security.context`` service.

The :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::createAccessDeniedException`
method creates a special :class:`Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException`
object, which ultimately triggers a 403 HTTP response inside Symfony.
In both cases, a special
:class:`Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException`
is thrown, which ultimately triggers a 403 HTTP response inside Symfony.

That's it! If the user isn't logged in yet, they will be asked to login (e.g.
redirected to the login page). If they *are* logged in, they'll be shown
Expand Down
2 changes: 1 addition & 1 deletion book/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ or perform more complex requests. Some useful examples::
array('photo' => $photo)
);

// Perform a DELETE requests and pass HTTP headers
// Perform a DELETE request and pass HTTP headers
$client->request(
'DELETE',
'/post/12',
Expand Down
2 changes: 1 addition & 1 deletion book/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ workflow looks like the following from inside a controller::
if ($form->isValid()) {
// the validation passed, do something with the $author object

return $this->redirect($this->generateUrl(...));
return $this->redirectToRoute(...);
}

return $this->render('author/form.html.twig', array(
Expand Down
7 changes: 7 additions & 0 deletions components/asset/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Asset
=====

.. toctree::
:maxdepth: 2

introduction
Loading

0 comments on commit f24c84f

Please sign in to comment.