Skip to content

Instantly share code, notes, and snippets.

@EuphoryX1
Last active December 12, 2015 02:08
Show Gist options
  • Select an option

  • Save EuphoryX1/4696289 to your computer and use it in GitHub Desktop.

Select an option

Save EuphoryX1/4696289 to your computer and use it in GitHub Desktop.
translationを使わずメッセージリソースを管理する
#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%]
<?php
namespace Euphory\StoreBundle\Entity;
class GenericResource
{
public $resource;
public function __construct($resource)
{
$this->resource = $resource;
}
}
<?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,
);
}
}
{{ tpl.message.submit }}
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