Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Removed invalid examples#8986

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
javiereguiluz merged 4 commits intosymfony:4.0fromTheDevilOnLine:patch-2
Jan 7, 2018
Merged
Show file tree
Hide file tree
Changes fromall commits
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
26 changes: 21 additions & 5 deletionsbest_practices/security.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -238,12 +238,20 @@ more advanced use-case, you can always do the same security check in PHP:
// equivalent code without using the "denyAccessUnlessGranted()" shortcut:
//
// use Symfony\Component\Security\Core\Exception\AccessDeniedException;
// use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
//
// ...
//
// public function __construct(AuthorizationCheckerInterface $authorizationChecker) {
// $this->authorizationChecker = $authorizationChecker;
// }
//
// ...
//
// if (!$this->get('security.authorization_checker')->isGranted('edit', $post)) {
// if (!$this->authorizationChecker->isGranted('edit', $post)) {
// throw $this->createAccessDeniedException();
// }

//
// ...
}

Expand DownExpand Up@@ -357,14 +365,22 @@ via the even easier shortcut in a controller:

$this->denyAccessUnlessGranted('edit', $post);

// or without the shortcut:
//
// use Symfony\Component\Security\Core\Exception\AccessDeniedException;
// use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
//
// ...
//
// if (!$this->get('security.authorization_checker')->isGranted('edit', $post)) {
// public function __construct(AuthorizationCheckerInterface $authorizationChecker) {
// $this->authorizationChecker = $authorizationChecker;
// }
//
// ...
//
// if (!$this->authorizationChecker->isGranted('edit', $post)) {
// throw $this->createAccessDeniedException();
// }
//
// ...
}

Learn More
Expand Down
27 changes: 0 additions & 27 deletionscontroller.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -290,33 +290,6 @@ in your controllers.

For more information about services, see the :doc:`/service_container` article.

.. _controller-access-services-directly:

Accessing the Container Directly
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you extend the base ``Controller`` class, you can access :ref:`public services <container-public>`
via the :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::get`
method. Here are several common services you might need::

$templating = $this->get('templating');

$router = $this->get('router');

$mailer = $this->get('mailer');

// you can also fetch parameters
$someParameter = $this->getParameter('some_parameter');

If you receive an error like:

.. code-block:: text

You have requested a non-existent service "my_service_id"

Check to make sure the service exists (use :ref:`debug:container <container-debug-container>`)
and that it's :ref:`public <container-public>`.

.. index::
single: Controller; Managing errors
single: Controller; 404 pages
Expand Down
7 changes: 5 additions & 2 deletionsdoctrine/multiple_entity_managers.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -231,11 +231,14 @@ the default entity manager (i.e. ``default``) is returned::

// ...

use Doctrine\ORM\EntityManagerInterface;

class UserController extends Controller
{
public function indexAction()
public function indexAction(EntityManagerInterface $em)
{
// All 3 return the "default" entity manager
// These methods also return the default entity manager, but it's preferred
// to get it by inyecting EntityManagerInterface in the action method
$em = $this->getDoctrine()->getManager();
$em = $this->getDoctrine()->getManager('default');
$em = $this->get('doctrine.orm.default_entity_manager');
Expand Down
2 changes: 1 addition & 1 deletionrouting.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -576,7 +576,7 @@ Generating URLs with Query Strings
The ``generate()`` method takes an array of wildcard values to generate the URI.
But if you pass extra ones, they will be added to the URI as a query string::

$this->get('router')->generate('blog', array(
$this->router->generate('blog', array(
'page' => 2,
'category' => 'Symfony'
));
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp