Last active
December 12, 2015 02:08
-
-
Save EuphoryX1/4696289 to your computer and use it in GitHub Desktop.
translationを使わずメッセージリソースを管理する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #config.ymlなどでparameters, servicesを定義 | |
| parameters: | |
| message_resource.class: Euphory\StoreBundle\Entity\GenericResource | |
| message_resource.message: | |
| submit: "送信" | |
| services: | |
| message_resource: | |
| class: "%message_resource.class%" | |
| arguments: [%message_resource.message%] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Euphory\StoreBundle\Entity; | |
| class GenericResource | |
| { | |
| public $resource; | |
| public function __construct($resource) | |
| { | |
| $this->resource = $resource; | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @Template("EuphoryStoreBundle:Default:form.html.twig") | |
| */ | |
| class fooController extends Controller | |
| { | |
| public function formAction() | |
| { | |
| $messageResource = $this->get('message_resource'); | |
| $tpl = new \stdClass(); | |
| $tpl->message = $messageResource->resource; | |
| return array( | |
| 'tpl' => $tpl, | |
| ); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {{ tpl.message.submit }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1. config.ymlなどでparameters, servicesを定義 | |
| 2. サービスコンテナを定義 | |
| 3. コントローラ内でサービスコンテナを取得 | |
| 4. テンプレートへ渡す |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment