From 7c3d36ab56a2fc6d8cddc709deae34b50c55ad2a Mon Sep 17 00:00:00 2001 From: polidog Date: Fri, 31 Oct 2014 01:03:32 +0900 Subject: [PATCH 01/35] =?UTF-8?q?=E7=BF=BB=E8=A8=B3=E3=81=AE=E9=80=94?= =?UTF-8?q?=E4=B8=AD...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- best_practices/controllers.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 best_practices/controllers.rst diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst new file mode 100644 index 0000000..d60aa8d --- /dev/null +++ b/best_practices/controllers.rst @@ -0,0 +1,22 @@ +コントローラー +=========== + +Symfonyは薄いコントローラとファットなモデルという哲学に従います。 この哲学が意味する事は、様々な +アプリケーションを扱うに為にグルーコードな薄いコントローラを維持する事が必要だという事です。 + +経験則として、正確な基準はありませんが、コントローラに定義する変数は5個以下、 +アクションの数が10個以下で、各アクション内の行数は20行以内という「5-10-20ルール」に従う事は +コードをコントローラからサービスにリファクタリングする際に役に立ちます。 + +.. best-practice:: + + あなたがコントローラを作る場合``FrameworkBundle``のコントローラを継承し, + 可能な限り、ルーティング、キャッシングとセキュリティをアノテーションで設定してください。 + + +コントローラとフレームワークを連携させることで、フレームワークの機能すべてを +活用する事を可能にし、あなたの生産性を向上させます。 + +そして、コントローラーは薄く、数行のグルーコードであるべきで、 +フレームワークからそれらを切り離すそうとすると、時間かかるので長期的に見ると利益になりません。 +大量の時間を費やすだけで、何の価値もありません。 From cd977540ac548790c46be075febda4a42d48a4d9 Mon Sep 17 00:00:00 2001 From: polidog Date: Sun, 16 Nov 2014 02:25:20 +0900 Subject: [PATCH 02/35] =?UTF-8?q?=E3=82=AD=E3=83=A3=E3=83=83=E3=82=B7?= =?UTF-8?q?=E3=83=B3=E3=82=B0=E3=82=92=E3=82=AD=E3=83=A3=E3=83=83=E3=82=B7?= =?UTF-8?q?=E3=83=A5=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- best_practices/controllers.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index d60aa8d..41c6ac1 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -11,7 +11,7 @@ Symfonyは薄いコントローラとファットなモデルという哲学に .. best-practice:: あなたがコントローラを作る場合``FrameworkBundle``のコントローラを継承し, - 可能な限り、ルーティング、キャッシングとセキュリティをアノテーションで設定してください。 + 可能な限り、ルーティング、キャッシュとセキュリティをアノテーションで設定してください。 コントローラとフレームワークを連携させることで、フレームワークの機能すべてを From 905390aed21717cbe191703c68c9958caca1f558 Mon Sep 17 00:00:00 2001 From: polidog Date: Sun, 16 Nov 2014 03:23:48 +0900 Subject: [PATCH 03/35] =?UTF-8?q?=E3=83=AB=E3=83=BC=E3=83=86=E3=82=A3?= =?UTF-8?q?=E3=83=B3=E3=82=B0=E3=81=AE=E8=A8=AD=E5=AE=9A=E3=82=89=E3=81=B8?= =?UTF-8?q?=E3=82=93=E3=81=BE=E3=81=A7=E8=A8=98=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- best_practices/controllers.rst | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 41c6ac1..2569e3c 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -1,8 +1,7 @@ コントローラー =========== - -Symfonyは薄いコントローラとファットなモデルという哲学に従います。 この哲学が意味する事は、様々な -アプリケーションを扱うに為にグルーコードな薄いコントローラを維持する事が必要だという事です。 +Symfonyは薄いコントローラとファットなモデルという哲学に従います。 つまり、コントローラは、 +アプリケーションの様々な部分をとりまとめるグルーコードだけからなる薄いレイヤーにするべきです。 経験則として、正確な基準はありませんが、コントローラに定義する変数は5個以下、 アクションの数が10個以下で、各アクション内の行数は20行以内という「5-10-20ルール」に従う事は @@ -10,7 +9,7 @@ Symfonyは薄いコントローラとファットなモデルという哲学に .. best-practice:: - あなたがコントローラを作る場合``FrameworkBundle``のコントローラを継承し, + 開発者がコントローラを作る場合``FrameworkBundle``のコントローラを継承し、 可能な限り、ルーティング、キャッシュとセキュリティをアノテーションで設定してください。 @@ -20,3 +19,23 @@ Symfonyは薄いコントローラとファットなモデルという哲学に そして、コントローラーは薄く、数行のグルーコードであるべきで、 フレームワークからそれらを切り離すそうとすると、時間かかるので長期的に見ると利益になりません。 大量の時間を費やすだけで、何の価値もありません。 + +加えて、 ルーティング、キャッシュ、セキュリティに対してアノテーションを使用すると簡単に設定する事ができます。 +すべての設定は必要な場所に一つのフォーマットにすれば、YAML, XML, PHPなどの複数ファイルを見る必要がなくなります。 + +全体的にビジネスロジックをフレームワークから切り離すという手段は積極的に行うと +同時に、最大限に活用にするためにルーティングとコントローラは結合するべきです。 + +ルーティング設定 +--------------------- + +コントローラで定義されたアノテーションを利用するにはrouting.ymlに以下の設定を追加します。 + +.. code-block:: yaml + + # app/config/routing.yml + app: + resource: "@AppBundle/Controller/" + type: annotation + + From c5fd41390d4f3dfd57e7db1d12ca49a6d13b3af8 Mon Sep 17 00:00:00 2001 From: polidog Date: Sun, 16 Nov 2014 03:56:34 +0900 Subject: [PATCH 04/35] =?UTF-8?q?template=E3=81=AE=E3=82=A2=E3=83=8E?= =?UTF-8?q?=E3=83=86=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E3=81=AB=E9=96=A2?= =?UTF-8?q?=E3=81=97=E3=81=A6=E3=81=AE=E5=85=88=E9=A0=AD=E9=83=A8=E5=88=86?= =?UTF-8?q?=E3=82=92=E7=BF=BB=E8=A8=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- best_practices/controllers.rst | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 2569e3c..2c2d49b 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -38,4 +38,32 @@ Symfonyは薄いコントローラとファットなモデルという哲学に resource: "@AppBundle/Controller/" type: annotation - +``src/AppBundle/Controller/`` ディレクトリとそのサブディレクトリからコントローラの +アノテーションをロードします。 +もしアプリケーションに多くのコントローラがある場合、それらをサブディレクトリへ移動する事が可能です。 + +.. code-block:: text + + / + ├─ ... + └─ src/ + └─ AppBundle/ + ├─ ... + └─ Controller/ + ├─ DefaultController.php + ├─ ... + ├─ Api/ + │ ├─ ... + │ └─ ... + └─ Backend/ + ├─ ... + └─ ... + +テンプレート設定 +---------------------- + +.. best-practice:: + + テンプレートの設定は ``@Template()`` アノテーションを使用しないでください。 + +``@Template``は便利ですがいくつかの魔法を伴うので、お勧めする事はできません。 From 75da09877691f4102ab11fd47c83bf0be103897e Mon Sep 17 00:00:00 2001 From: polidog Date: Mon, 17 Nov 2014 02:35:04 +0900 Subject: [PATCH 05/35] =?UTF-8?q?=E3=82=A2=E3=83=8E=E3=83=86=E3=83=BC?= =?UTF-8?q?=E3=82=B7=E3=83=A7=E3=83=B3=E9=83=A8=E5=88=86=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E8=A8=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- best_practices/controllers.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 2c2d49b..b94d263 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -67,3 +67,7 @@ Symfonyは薄いコントローラとファットなモデルという哲学に テンプレートの設定は ``@Template()`` アノテーションを使用しないでください。 ``@Template``は便利ですがいくつかの魔法を伴うので、お勧めする事はできません。 + +ほとんどの場合、``@Template``はパラメータの設定をせず使用されます。そして設定すると、どの +テンプレートを表示するかをわかりづらくします。それはまた、必ずコントローラはレスポンスオブジェクトを +返すべきだと言う事を初心者にわかりにくくしてしまいます。(あなたがビューレイヤーを利用している場合以外) From 7fde34cfb6502d65f2b7ebbc653aa55135edb017 Mon Sep 17 00:00:00 2001 From: polidog Date: Fri, 21 Nov 2014 02:15:42 +0900 Subject: [PATCH 06/35] =?UTF-8?q?=E3=82=82=E3=81=86=E3=81=99=E3=81=93?= =?UTF-8?q?=E3=81=97=E3=81=99=E3=81=99=E3=82=93=E3=81=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- best_practices/controllers.rst | 126 +++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index b94d263..26db166 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -71,3 +71,129 @@ Symfonyは薄いコントローラとファットなモデルという哲学に ほとんどの場合、``@Template``はパラメータの設定をせず使用されます。そして設定すると、どの テンプレートを表示するかをわかりづらくします。それはまた、必ずコントローラはレスポンスオブジェクトを 返すべきだと言う事を初心者にわかりにくくしてしまいます。(あなたがビューレイヤーを利用している場合以外) + +最後に、@Templateアノテーションはkernel.viewイベントのイベントディスパッチのフックとして +TemplateListenerクラスで利用されます。そのリスナーのパフォーマンスへの影響を紹介します。 +ブログのサンプルアプリケーションのホームページをレンダリングする場合、$this->render()メソッドを +使った場合5ミリ秒かかり、@Templateアノテーションを使った場合26ミリ秒かかりました。 + +How the Controller Looks +------------------------ + +Considering all this, here is an example of how the controller should look +for the homepage of our app: + +.. code-block:: php + + namespace AppBundle\Controller; + + use Symfony\Bundle\FrameworkBundle\Controller\Controller; + use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; + + class DefaultController extends Controller + { + /** + * @Route("/", name="homepage") + */ + public function indexAction() + { + $em = $this->getDoctrine()->getManager(); + $posts = $em->getRepository('App:Post')->findLatest(); + + return $this->render('default/index.html.twig', array( + 'posts' => $posts + )); + } + } + +.. _best-practices-paramconverter: + +ParamConverterを使う +------------------------ + +もしDoctrineを使っている場合は必要に応じて`ParamConverter`_ を使い、自動的にエンティティを取得し、 +コントローラの引数として渡す必要があります。 + +.. best-practice:: + + シンプルかつ簡単な場合は、自動的にDoctrineのエンティティを取得出来るParamConverterを使用 + してください。 + +例: + +.. code-block:: php + + /** + * @Route("/{id}", name="admin_post_show") + */ + public function showAction(Post $post) + { + $deleteForm = $this->createDeleteForm($post); + + return $this->render('admin/post/show.html.twig', array( + 'post' => $post, + 'delete_form' => $deleteForm->createView(), + )); + } + +通常は ``showAction`` では ``$id`` という変数を引数として使うと思います。 +代わりに ``$post`` 引数と ``Post`` クラス(Doctrineのエンティティ)をタイプヒンティングする +ことによって、そのオブジェクトを自動的にParamConverterが``{id}`` の値と一致する +``$id`` プロパティのものを取得します。``Post`` が見つからなかった場合は404ページが表示されます。 + +高度な事 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This works without any configuration +This works without any configuration because the wildcard name ``{id}`` matches +the name of the property on the entity. If this isn't true, or if you have +even more complex logic, the easiest thing to do is just query for the entity +manually. In our application, we have this situation in ``CommentController``: + +.. code-block:: php + + /** + * @Route("/comment/{postSlug}/new", name = "comment_new") + */ + public function newAction(Request $request, $postSlug) + { + $post = $this->getDoctrine() + ->getRepository('AppBundle:Post') + ->findOneBy(array('slug' => $postSlug)); + + if (!$post) { + throw $this->createNotFoundException(); + } + + // ... + } + +You can also use the ``@ParamConverter`` configuration, which is infinitely +flexible: + +.. code-block:: php + + use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; + use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; + + /** + * @Route("/comment/{postSlug}/new", name = "comment_new") + * @ParamConverter("post", options={"mapping": {"postSlug": "slug"}}) + */ + public function newAction(Request $request, Post $post) + { + // ... + } + +The point is this: the ParamConverter shortcut is great for simple situations. +But you shouldn't forget that querying for entities directly is still very +easy. + +Pre and Post Hooks +------------------ + +If you need to execute some code before or after the execution of your controllers, +you can use the EventDispatcher component to `set up before/after filters`_. + +.. _`ParamConverter`: http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html +.. _`set up before/after filters`: http://symfony.com/doc/current/cookbook/event_dispatcher/before_after_filters.html From b908c6e7065ac2643b4d416802a875b0ac563ae6 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 10:16:05 +0900 Subject: [PATCH 07/35] apply https://github.com/symfony-japan/symfony-docs-ja/pull/319#discussion_r21287150 --- best_practices/controllers.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 26db166..17a173e 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -3,9 +3,10 @@ Symfonyは薄いコントローラとファットなモデルという哲学に従います。 つまり、コントローラは、 アプリケーションの様々な部分をとりまとめるグルーコードだけからなる薄いレイヤーにするべきです。 -経験則として、正確な基準はありませんが、コントローラに定義する変数は5個以下、 -アクションの数が10個以下で、各アクション内の行数は20行以内という「5-10-20ルール」に従う事は -コードをコントローラからサービスにリファクタリングする際に役に立ちます。 +だいたいの目安として、次の「5-10-20ルール」に従うとよいでしょう。 +1つのコントローラで定義する変数を5個以下にすること、含まれるアクションを10個以下にすること、1つのアクションのコード行数を20行以下にすること。 +この数字に科学的な根拠はありませんが、コントローラーからサービスへリファクタリングすべきタイミングを見極める基準としては役立ちます。 + .. best-practice:: From 1e19c51ce33b5b9e5c12741c8ed2b1064c53cb71 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 10:22:07 +0900 Subject: [PATCH 08/35] refine best-practice --- best_practices/controllers.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 17a173e..6ff1476 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -10,8 +10,8 @@ Symfonyは薄いコントローラとファットなモデルという哲学に .. best-practice:: - 開発者がコントローラを作る場合``FrameworkBundle``のコントローラを継承し、 - 可能な限り、ルーティング、キャッシュとセキュリティをアノテーションで設定してください。 + コントローラを作る場合``FrameworkBundle``のベースコントローラを継承し、 + ルーティング、キャッシュ、セキュリティを設定するときはなるべくアノテーションを使ってください。 コントローラとフレームワークを連携させることで、フレームワークの機能すべてを From 110c3e7afc8d05fc119f1c6fd26f9e294699a7b5 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 10:26:37 +0900 Subject: [PATCH 09/35] refine document --- best_practices/controllers.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 6ff1476..ac1e0c0 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -14,8 +14,8 @@ Symfonyは薄いコントローラとファットなモデルという哲学に ルーティング、キャッシュ、セキュリティを設定するときはなるべくアノテーションを使ってください。 -コントローラとフレームワークを連携させることで、フレームワークの機能すべてを -活用する事を可能にし、あなたの生産性を向上させます。 +コントローラを基底フレームワークに結合させることで、フレームワークの機能すべてを +活用する事が可能になり、生産性が向上します。 そして、コントローラーは薄く、数行のグルーコードであるべきで、 フレームワークからそれらを切り離すそうとすると、時間かかるので長期的に見ると利益になりません。 From 258c1bc8f4bd4b50463def16dcf45f6063d4d3a0 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 10:31:47 +0900 Subject: [PATCH 10/35] refine document --- best_practices/controllers.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index ac1e0c0..db221a1 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -17,9 +17,9 @@ Symfonyは薄いコントローラとファットなモデルという哲学に コントローラを基底フレームワークに結合させることで、フレームワークの機能すべてを 活用する事が可能になり、生産性が向上します。 -そして、コントローラーは薄く、数行のグルーコードであるべきで、 -フレームワークからそれらを切り離すそうとすると、時間かかるので長期的に見ると利益になりません。 -大量の時間を費やすだけで、何の価値もありません。 +コントローラーは薄く数行のグルー(糊)コードであるべきです。何時間もかけてコントローラを +フレームワークから切り離そうとしても、長期的にはメリットがありません。 +それに時間を費やしても何の価値もありません。 加えて、 ルーティング、キャッシュ、セキュリティに対してアノテーションを使用すると簡単に設定する事ができます。 すべての設定は必要な場所に一つのフォーマットにすれば、YAML, XML, PHPなどの複数ファイルを見る必要がなくなります。 From 1bc22d9b117d96985b6569703ec0fb8589c91a30 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 10:33:51 +0900 Subject: [PATCH 11/35] improve wording --- best_practices/controllers.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index db221a1..529e166 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -1,6 +1,6 @@ コントローラー =========== -Symfonyは薄いコントローラとファットなモデルという哲学に従います。 つまり、コントローラは、 +Symfonyは薄いコントローラとファットなモデルという哲学を信奉します。 つまり、コントローラは、 アプリケーションの様々な部分をとりまとめるグルーコードだけからなる薄いレイヤーにするべきです。 だいたいの目安として、次の「5-10-20ルール」に従うとよいでしょう。 From f0c256566503e1879d4dbf3e377e072e66f11920 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 10:36:17 +0900 Subject: [PATCH 12/35] refine document --- best_practices/controllers.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 529e166..4158522 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -21,7 +21,7 @@ Symfonyは薄いコントローラとファットなモデルという哲学を フレームワークから切り離そうとしても、長期的にはメリットがありません。 それに時間を費やしても何の価値もありません。 -加えて、 ルーティング、キャッシュ、セキュリティに対してアノテーションを使用すると簡単に設定する事ができます。 +加えて、 ルーティング、キャッシュ、セキュリティに対してアノテーションを使えば設定がシンプルになります。 すべての設定は必要な場所に一つのフォーマットにすれば、YAML, XML, PHPなどの複数ファイルを見る必要がなくなります。 全体的にビジネスロジックをフレームワークから切り離すという手段は積極的に行うと From bd4dd984ca02cda861bfe7419e521b1fac3ba33e Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 10:40:02 +0900 Subject: [PATCH 13/35] refine document --- best_practices/controllers.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 4158522..46318cf 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -22,7 +22,9 @@ Symfonyは薄いコントローラとファットなモデルという哲学を それに時間を費やしても何の価値もありません。 加えて、 ルーティング、キャッシュ、セキュリティに対してアノテーションを使えば設定がシンプルになります。 -すべての設定は必要な場所に一つのフォーマットにすれば、YAML, XML, PHPなどの複数ファイルを見る必要がなくなります。 +そうすれば、 +YAML, XML, PHPなどのいろんなフォーマットで作られた何十もの設定ファイルを見る必要はなくなります。全ての設定は必要な場所に収まり、1つのフォーマットで済むでしょう。 + 全体的にビジネスロジックをフレームワークから切り離すという手段は積極的に行うと 同時に、最大限に活用にするためにルーティングとコントローラは結合するべきです。 From 6fb13dd74a06e454e401dc519799238f4db3683e Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 10:44:22 +0900 Subject: [PATCH 14/35] refine document --- best_practices/controllers.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 46318cf..8967acf 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -26,8 +26,10 @@ Symfonyは薄いコントローラとファットなモデルという哲学を YAML, XML, PHPなどのいろんなフォーマットで作られた何十もの設定ファイルを見る必要はなくなります。全ての設定は必要な場所に収まり、1つのフォーマットで済むでしょう。 -全体的にビジネスロジックをフレームワークから切り離すという手段は積極的に行うと -同時に、最大限に活用にするためにルーティングとコントローラは結合するべきです。 +あなたのビジネスロジックをフレームワークから切り離しながらも、 +同時に、ルーティングとコントローラはフレームワークに積極的に結合するべきということです。 +そうすればフレームワークを最大限活用できるでしょう。 + ルーティング設定 --------------------- From 20d91a9f13260b1ee59a2430958e756e0084417c Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 10:45:02 +0900 Subject: [PATCH 15/35] refine document --- best_practices/controllers.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 8967acf..7768ff0 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -1,7 +1,7 @@ コントローラー =========== Symfonyは薄いコントローラとファットなモデルという哲学を信奉します。 つまり、コントローラは、 -アプリケーションの様々な部分をとりまとめるグルーコードだけからなる薄いレイヤーにするべきです。 +アプリケーションの様々な部分をとりまとめるグルー(糊)コードだけからなる薄いレイヤーにするべきです。 だいたいの目安として、次の「5-10-20ルール」に従うとよいでしょう。 1つのコントローラで定義する変数を5個以下にすること、含まれるアクションを10個以下にすること、1つのアクションのコード行数を20行以下にすること。 @@ -17,7 +17,7 @@ Symfonyは薄いコントローラとファットなモデルという哲学を コントローラを基底フレームワークに結合させることで、フレームワークの機能すべてを 活用する事が可能になり、生産性が向上します。 -コントローラーは薄く数行のグルー(糊)コードであるべきです。何時間もかけてコントローラを +コントローラーは薄く数行のグルーコードであるべきです。何時間もかけてコントローラを フレームワークから切り離そうとしても、長期的にはメリットがありません。 それに時間を費やしても何の価値もありません。 From d77d16a284b5487b098254f938267e60cfe2a3b5 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 10:45:27 +0900 Subject: [PATCH 16/35] refine document --- best_practices/controllers.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 7768ff0..a00a434 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -1,7 +1,6 @@ コントローラー =========== -Symfonyは薄いコントローラとファットなモデルという哲学を信奉します。 つまり、コントローラは、 -アプリケーションの様々な部分をとりまとめるグルー(糊)コードだけからなる薄いレイヤーにするべきです。 +Symfonyは薄いコントローラとファットなモデルという哲学を信奉します。 つまり、コントローラはアプリケーションの様々な部分をとりまとめるグルー(糊)コードだけからなる薄いレイヤーにするべきです。 だいたいの目安として、次の「5-10-20ルール」に従うとよいでしょう。 1つのコントローラで定義する変数を5個以下にすること、含まれるアクションを10個以下にすること、1つのアクションのコード行数を20行以下にすること。 From f94b728f4b5557ff76a88d38f8aa5c298b162f16 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 10:46:09 +0900 Subject: [PATCH 17/35] more readable --- best_practices/controllers.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index a00a434..d963b31 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -3,7 +3,7 @@ Symfonyは薄いコントローラとファットなモデルという哲学を信奉します。 つまり、コントローラはアプリケーションの様々な部分をとりまとめるグルー(糊)コードだけからなる薄いレイヤーにするべきです。 だいたいの目安として、次の「5-10-20ルール」に従うとよいでしょう。 -1つのコントローラで定義する変数を5個以下にすること、含まれるアクションを10個以下にすること、1つのアクションのコード行数を20行以下にすること。 +1コントローラで定義する変数を5個以下にすること、含まれるアクションを10個以下にすること、1アクションのコード行数を20行以下にすること。 この数字に科学的な根拠はありませんが、コントローラーからサービスへリファクタリングすべきタイミングを見極める基準としては役立ちます。 From 72d726a70e74fac56c7b418bad3c9a2aaa152a59 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 10:47:23 +0900 Subject: [PATCH 18/35] =?UTF-8?q?=E3=80=8C=E3=82=B3=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=83=A9=E3=80=8D=E3=81=A7=E7=B5=B1=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- best_practices/controllers.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index d963b31..d6d0107 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -16,7 +16,7 @@ Symfonyは薄いコントローラとファットなモデルという哲学を コントローラを基底フレームワークに結合させることで、フレームワークの機能すべてを 活用する事が可能になり、生産性が向上します。 -コントローラーは薄く数行のグルーコードであるべきです。何時間もかけてコントローラを +コントローラは薄く数行のグルーコードであるべきです。何時間もかけてコントローラを フレームワークから切り離そうとしても、長期的にはメリットがありません。 それに時間を費やしても何の価値もありません。 From aae993a6101f984a24008f46dfefadae3b765f0d Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 10:50:41 +0900 Subject: [PATCH 19/35] improve wording --- best_practices/controllers.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index d6d0107..3a14a78 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -30,10 +30,11 @@ YAML, XML, PHPなどのいろんなフォーマットで作られた何十もの そうすればフレームワークを最大限活用できるでしょう。 -ルーティング設定 +ルーティングの設定 --------------------- -コントローラで定義されたアノテーションを利用するにはrouting.ymlに以下の設定を追加します。 + +コントローラでアノテーションとして定義されたルーティングを読み込むには、routing.ymlに以下の設定を追加します。 .. code-block:: yaml From e2ae95f94bc50aeb91daa656a80c3ad7a05ec2cb Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 10:53:47 +0900 Subject: [PATCH 20/35] improve wording --- best_practices/controllers.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 3a14a78..9def9f4 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -43,9 +43,9 @@ YAML, XML, PHPなどのいろんなフォーマットで作られた何十もの resource: "@AppBundle/Controller/" type: annotation -``src/AppBundle/Controller/`` ディレクトリとそのサブディレクトリからコントローラの -アノテーションをロードします。 -もしアプリケーションに多くのコントローラがある場合、それらをサブディレクトリへ移動する事が可能です。 +このように設定すると、``src/AppBundle/Controller/`` ディレクトリとそのサブディレクトリにあるコントローラのアノテーションを読み込んでくれます。・ +もしアプリケーションに多くのコントローラがある場合、それらをサブディレクトリへ移動しても全く問題ありません。 + .. code-block:: text From 8369140b383a65edd96caf1625fcff6f12d928ec Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 10:55:19 +0900 Subject: [PATCH 21/35] improve wording --- best_practices/controllers.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 9def9f4..73e5b03 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -44,7 +44,7 @@ YAML, XML, PHPなどのいろんなフォーマットで作られた何十もの type: annotation このように設定すると、``src/AppBundle/Controller/`` ディレクトリとそのサブディレクトリにあるコントローラのアノテーションを読み込んでくれます。・ -もしアプリケーションに多くのコントローラがある場合、それらをサブディレクトリへ移動しても全く問題ありません。 +もしアプリケーションに多くのコントローラがある場合、それらを下図のようにサブディレクトリを作ってその中に移動しても全く問題ありません。 .. code-block:: text From 44afbf42283928056837fb4edebbc99d5fb32e9d Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 10:56:27 +0900 Subject: [PATCH 22/35] improve wording --- best_practices/controllers.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 73e5b03..0e2a2e6 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -69,7 +69,7 @@ YAML, XML, PHPなどのいろんなフォーマットで作られた何十もの .. best-practice:: - テンプレートの設定は ``@Template()`` アノテーションを使用しないでください。 + コントローラから呼ばれるテンプレートの設定をするのに ``@Template()`` アノテーションを使用しないでください。 ``@Template``は便利ですがいくつかの魔法を伴うので、お勧めする事はできません。 From 0051fd62f7d107fc9c5b9a5eda61487b6e10ec73 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 11:31:06 +0900 Subject: [PATCH 23/35] improve wording --- best_practices/controllers.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 0e2a2e6..5a4014d 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -71,10 +71,10 @@ YAML, XML, PHPなどのいろんなフォーマットで作られた何十もの コントローラから呼ばれるテンプレートの設定をするのに ``@Template()`` アノテーションを使用しないでください。 -``@Template``は便利ですがいくつかの魔法を伴うので、お勧めする事はできません。 +``@Template``は便利ですがある種の魔法を伴います。魔法を使うに値するとは思えないのでお勧めしません。 -ほとんどの場合、``@Template``はパラメータの設定をせず使用されます。そして設定すると、どの -テンプレートを表示するかをわかりづらくします。それはまた、必ずコントローラはレスポンスオブジェクトを +ほとんどの場合、``@Template``はパラメータなしで使われますが、そうするとどのテンプレートが呼ばれるのかわかりづらくなります。 +それはまた、必ずコントローラはレスポンスオブジェクトを 返すべきだと言う事を初心者にわかりにくくしてしまいます。(あなたがビューレイヤーを利用している場合以外) 最後に、@Templateアノテーションはkernel.viewイベントのイベントディスパッチのフックとして From 90692d7302773f74f2a93711a6c81d0ea0de8d2d Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 11:32:47 +0900 Subject: [PATCH 24/35] improve wording --- best_practices/controllers.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 5a4014d..14cb09a 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -74,8 +74,7 @@ YAML, XML, PHPなどのいろんなフォーマットで作られた何十もの ``@Template``は便利ですがある種の魔法を伴います。魔法を使うに値するとは思えないのでお勧めしません。 ほとんどの場合、``@Template``はパラメータなしで使われますが、そうするとどのテンプレートが呼ばれるのかわかりづらくなります。 -それはまた、必ずコントローラはレスポンスオブジェクトを -返すべきだと言う事を初心者にわかりにくくしてしまいます。(あなたがビューレイヤーを利用している場合以外) +また、コントローラは必ずレスポンスオブジェクトを返すべきだと言う事を初心者にわかりにくくします。(ビューレイヤーを使わない場合) 最後に、@Templateアノテーションはkernel.viewイベントのイベントディスパッチのフックとして TemplateListenerクラスで利用されます。そのリスナーのパフォーマンスへの影響を紹介します。 From 03031752769513a4b0eed2e227854c25893d5e3e Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 11:35:00 +0900 Subject: [PATCH 25/35] translate --- best_practices/controllers.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 14cb09a..143a401 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -81,11 +81,10 @@ TemplateListenerクラスで利用されます。そのリスナーのパフォ ブログのサンプルアプリケーションのホームページをレンダリングする場合、$this->render()メソッドを 使った場合5ミリ秒かかり、@Templateアノテーションを使った場合26ミリ秒かかりました。 -How the Controller Looks +コントローラはこんな感じにしよう ------------------------ -Considering all this, here is an example of how the controller should look -for the homepage of our app: +上記のことをふまえると、アプリケーションのホームページを表示するコントローラはこんな感じにするのがよいでしょう。 .. code-block:: php From ec2b0739834e4f39838de43b18dbdc73d4c635c4 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 11:35:49 +0900 Subject: [PATCH 26/35] use latest version --- best_practices/controllers.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 143a401..bcd8127 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -100,8 +100,9 @@ TemplateListenerクラスで利用されます。そのリスナーのパフォ */ public function indexAction() { - $em = $this->getDoctrine()->getManager(); - $posts = $em->getRepository('App:Post')->findLatest(); + $posts = $this->getDoctrine() + ->getRepository('AppBundle:Post') + ->findLatest(); return $this->render('default/index.html.twig', array( 'posts' => $posts @@ -109,6 +110,7 @@ TemplateListenerクラスで利用されます。そのリスナーのパフォ } } + .. _best-practices-paramconverter: ParamConverterを使う From 2d780a9732ebdd65d85a6b08e8c11be3470069ad Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 11:39:46 +0900 Subject: [PATCH 27/35] refine document --- best_practices/controllers.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index bcd8127..e109437 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -116,13 +116,13 @@ TemplateListenerクラスで利用されます。そのリスナーのパフォ ParamConverterを使う ------------------------ -もしDoctrineを使っている場合は必要に応じて`ParamConverter`_ を使い、自動的にエンティティを取得し、 -コントローラの引数として渡す必要があります。 +Doctrineを使っている場合は`ParamConverter`_ を使うことができます。 +これは自動的にエンティティを取得し、コントローラの引数にしてくれます。 .. best-practice:: - シンプルかつ簡単な場合は、自動的にDoctrineのエンティティを取得出来るParamConverterを使用 - してください。 + Doctrineのエンティティを自動的に取得してくれるParamConverterを使用 + してください。もしそれがシンプルかつ有用な場合は。 例: From 46103a083cb11ebd0f221e269003a4f39f1fa3b3 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 11:46:28 +0900 Subject: [PATCH 28/35] update code block --- best_practices/controllers.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index e109437..48a8b77 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -128,6 +128,9 @@ Doctrineを使っている場合は`ParamConverter`_ を使うことができま .. code-block:: php + use AppBundle\Entity\Post; + use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; + /** * @Route("/{id}", name="admin_post_show") */ @@ -136,7 +139,7 @@ Doctrineを使っている場合は`ParamConverter`_ を使うことができま $deleteForm = $this->createDeleteForm($post); return $this->render('admin/post/show.html.twig', array( - 'post' => $post, + 'post' => $post, 'delete_form' => $deleteForm->createView(), )); } From d2d998613592283abc8f49bdc268a35a0803f146 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 11:50:24 +0900 Subject: [PATCH 29/35] =?UTF-8?q?=E6=9C=80=E6=96=B0=E3=81=AE=E8=8B=B1?= =?UTF-8?q?=E8=AA=9E=E7=89=88=E3=81=A7=E3=81=AF=E3=81=93=E3=82=8C=E3=81=AF?= =?UTF-8?q?=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F=E3=81=AE=E3=81=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- best_practices/controllers.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 48a8b77..7ad4bec 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -76,11 +76,6 @@ YAML, XML, PHPなどのいろんなフォーマットで作られた何十もの ほとんどの場合、``@Template``はパラメータなしで使われますが、そうするとどのテンプレートが呼ばれるのかわかりづらくなります。 また、コントローラは必ずレスポンスオブジェクトを返すべきだと言う事を初心者にわかりにくくします。(ビューレイヤーを使わない場合) -最後に、@Templateアノテーションはkernel.viewイベントのイベントディスパッチのフックとして -TemplateListenerクラスで利用されます。そのリスナーのパフォーマンスへの影響を紹介します。 -ブログのサンプルアプリケーションのホームページをレンダリングする場合、$this->render()メソッドを -使った場合5ミリ秒かかり、@Templateアノテーションを使った場合26ミリ秒かかりました。 - コントローラはこんな感じにしよう ------------------------ From d09ddd832ea251f963ebc4d18481ad588053b5bb Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 11:54:47 +0900 Subject: [PATCH 30/35] improve wording --- best_practices/controllers.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 7ad4bec..52e8456 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -139,10 +139,9 @@ Doctrineを使っている場合は`ParamConverter`_ を使うことができま )); } -通常は ``showAction`` では ``$id`` という変数を引数として使うと思います。 -代わりに ``$post`` 引数と ``Post`` クラス(Doctrineのエンティティ)をタイプヒンティングする -ことによって、そのオブジェクトを自動的にParamConverterが``{id}`` の値と一致する -``$id`` プロパティのものを取得します。``Post`` が見つからなかった場合は404ページが表示されます。 +通常、 ``showAction`` では ``$id`` という引数を期待するでしょう。その代わりに ``$post`` 引数を使い ``Post`` クラス(Doctrineのエンティティ)でタイプヒンティングすることで、 +とによって、そのオブジェクトをParamConverterが自動的に``{id}`` の値と一致する``$id`` プロパティを持つオブジェクトを探してくれます。 +また``Post`` が見つからなかった場合は404ページを表示してくれます。 高度な事 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From d38f234f6313e93811cb8304945278f65d944083 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 11:58:12 +0900 Subject: [PATCH 31/35] update to latest --- best_practices/controllers.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 52e8456..c9e0504 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -143,10 +143,9 @@ Doctrineを使っている場合は`ParamConverter`_ を使うことができま とによって、そのオブジェクトをParamConverterが自動的に``{id}`` の値と一致する``$id`` プロパティを持つオブジェクトを探してくれます。 また``Post`` が見つからなかった場合は404ページを表示してくれます。 -高度な事 +When Things Get More Advanced ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -This works without any configuration This works without any configuration because the wildcard name ``{id}`` matches the name of the property on the entity. If this isn't true, or if you have even more complex logic, the easiest thing to do is just query for the entity @@ -175,8 +174,10 @@ flexible: .. code-block:: php + use AppBundle\Entity\Post; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; + use Symfony\Component\HttpFoundation\Request; /** * @Route("/comment/{postSlug}/new", name = "comment_new") @@ -195,7 +196,7 @@ Pre and Post Hooks ------------------ If you need to execute some code before or after the execution of your controllers, -you can use the EventDispatcher component to `set up before/after filters`_. +you can use the EventDispatcher component to +:doc:`set up before and after filters `. -.. _`ParamConverter`: http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html -.. _`set up before/after filters`: http://symfony.com/doc/current/cookbook/event_dispatcher/before_after_filters.html +.. _`ParamConverter`: https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html From f8d89925247fb9f9b9ef6dadcd3317345f9755be Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 12:02:39 +0900 Subject: [PATCH 32/35] translate --- best_practices/controllers.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index c9e0504..5f1f677 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -146,10 +146,9 @@ Doctrineを使っている場合は`ParamConverter`_ を使うことができま When Things Get More Advanced ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -This works without any configuration because the wildcard name ``{id}`` matches -the name of the property on the entity. If this isn't true, or if you have -even more complex logic, the easiest thing to do is just query for the entity -manually. In our application, we have this situation in ``CommentController``: +上記のコードが設定なしで動くのは、ワイルドカード名``{id}``がエンティティのプロパティ名に一致するからです。 +もしそうでない場合、またはもっと複雑なロジックがある場合、これを実現する簡単な方法は手動でエンティティを取得することです。 +本アプリケーションでは``CommentController``がその事例です。: .. code-block:: php From 5effa17bdb7c4d019a1faea9b31284619ecdcf53 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 12:07:43 +0900 Subject: [PATCH 33/35] translate --- best_practices/controllers.rst | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 5f1f677..161e88e 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -168,8 +168,7 @@ When Things Get More Advanced // ... } -You can also use the ``@ParamConverter`` configuration, which is infinitely -flexible: +``@ParamConverter`` 設定を使うこともできます。そうすればどこまでも柔軟にできます。: .. code-block:: php @@ -187,9 +186,8 @@ flexible: // ... } -The point is this: the ParamConverter shortcut is great for simple situations. -But you shouldn't forget that querying for entities directly is still very -easy. +ポイントは、ParamConverterはシンプルなケースではよいということです。 +一方エンティティを直接取得するのも簡単にできるということを忘れないでください。 Pre and Post Hooks ------------------ From 25bd601179c4e1128b6caf86aa0cdd2be3e61670 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 12:07:47 +0900 Subject: [PATCH 34/35] translate --- best_practices/controllers.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index 161e88e..dc45efa 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -186,14 +186,13 @@ When Things Get More Advanced // ... } -ポイントは、ParamConverterはシンプルなケースではよいということです。 +ポイントは、ParamConverterはシンプルなケースでは素晴らしいということです。 一方エンティティを直接取得するのも簡単にできるということを忘れないでください。 -Pre and Post Hooks +事前フックと事後フック ------------------ -If you need to execute some code before or after the execution of your controllers, -you can use the EventDispatcher component to +もしコントローラの実行前後で任意のコードを実行したいなら、EventDipatcherコンポーネントを使うことができます。 :doc:`set up before and after filters `. .. _`ParamConverter`: https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html From 144ddcd66c81d2020fd4d87c3a988abef415caa2 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Sat, 4 Jul 2015 12:08:53 +0900 Subject: [PATCH 35/35] translate title --- best_practices/controllers.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index dc45efa..96ec6a1 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -143,7 +143,7 @@ Doctrineを使っている場合は`ParamConverter`_ を使うことができま とによって、そのオブジェクトをParamConverterが自動的に``{id}`` の値と一致する``$id`` プロパティを持つオブジェクトを探してくれます。 また``Post`` が見つからなかった場合は404ページを表示してくれます。 -When Things Get More Advanced +もっと複雑になったときは ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 上記のコードが設定なしで動くのは、ワイルドカード名``{id}``がエンティティのプロパティ名に一致するからです。