「ビューとレンダリング」セクションを和訳してみた。ほぼ直訳なのは勘弁。
この前のセクションまでは http://d.hatena.ne.jp/MugeSo/20071122/1195721363
Views and Rendering
-------------------
With the new concept of output types, Views may implement execute() methods specifically for an output type by containing an executeSomething() methods, with "something" being the name of the output type.
ビューとレンダリング
-------------------
出力タイプという新しい概念により、ビューに executeSomething() メソッドを含めることである出力タイプ(something)に特化した execute() の実装が可能になりました。
Inside the views, a lot has changed. Templates and Decorator Templates are gone, and instead, there are now template layers. Each layer has a template, and each layer may have slots. The layers may even use different renderers!Layers are rendered in the order they are defined, with the output of a rendered layer being available to the next layer's template as $inner (what used to be $template['content']).
ビューの内部には多くの変更があります。テンプレートとデコレーターテンプレートはなくなり、その代わりにテンプレートレイヤーがあります。それぞれのレイヤーはテンプレート、時としてスロットを持ちます。レイヤーは異なるレンダラーを用いることすらできます!レイヤーは定義された順番にレンダリングされます。すでにレンダリングされたレイヤーの出力は、次にレンダリングされるレイヤーのテンプレート内で、$inner(かつての $template['content'])として使用することができます。
For added convenience, the layers can be grouped together into layouts that are defined for each output type in output_types.xml. A simple call to loadLayout() in a view will load these layers and their slots.
さらなる利便性のために、レイヤーは、出力タイプ毎に output_types.xhml で定義されたとおりにレイアウトにグループ化することができます。ビューの中で loadLayout() を呼び出すだけで、これらのレイヤーとスロットがロードされます。
Each of the slots can be given additional request arguments to work with, as well as an output type different from the current container's. To create an execution container for a slot, createSlotContainer can be used for more convenience. But remember that in most cases, it's better to define the slots in the layout configuration.
それぞれのスロットには、現在のコンテナとは異なる出力タイプだけでなく、追加のリクエスト引数も渡すことができます。スロット用の実行コンテナを作成するために createSlotContainer() を使用することができます。しかしほとんどのケースではレイアウト設定でスロットを定義する方が良いでしょう。
The entire new layered rendering system is very flexible and allows runtime changes to already loaded layouts etc. For instance, you could inject an intermediate layer between two registered layers in one of your views, or you could retrieve a slot that has been loaded for you by loadLayout and then change it's output type or set additional request arguments.
完全に新しくなったレイヤー化されたレンダリングシステムはとてもフレキシブルで、実行時にすでにロードされたレイアウトを変更することさえ可能です。たとえば、登録された2つのレイヤーの間に中間レイヤーを差し込んだり、loadLayout でロードされたスロットを取り出してその出力タイプを変更したり、追加のリクエスト引数をセットすることができます。
Also, each layer is represented by a class, usually AgaviFileTemplateLayer, but there is a generic AgaviStreamTemplateLayer class that allows you to fetch templates from databases, via HTTP, through SSH tunnels or even from inline strings using data:// streams!And implementing a custom layer that reads templates from a database, without writing a PHP stream wrapper, is possible, too, and very easy to do!
それぞれのレイヤーは一つのクラスにより表されます。それは通常 AgaviFileTemplateLayer ですが、より包括的な AgaviStreamTemplateLayer クラスもあります。AgaviStreamTemplateLayer クラスを使えば、テンプレートをデータベースや HTTP、SSH トンネリング通信、data:// ストリームを使えばインライン文字列からさえ取得することができます。データベースからテンプレートを読み込むカスタムレイヤーの実装のために PHP ストリームラッパーを書く必要はありません。とても簡単です!
It's a tad more complicated than the old system, and it needs getting used to, but it is all you ever wanted ;) Check out the documentation for it to learn more and see additional examples of what it's capable of.
このシステムは旧来のシステムよりも少し複雑で、慣れを必要としますが、これが本当に必要とされていたものなのです ;) さらに詳しく知るにはドキュメントを読んでください。
Also, you don't specify the template extension anymore when setting template names. The extension automatically appended by the system will be the default one for the specific renderer (.php, .tpl etc) unless you explicitly specify an extension you want to use instead. One of the reasons why this is done is that if you have i18n enabled, Agavi will automatically look for localized versions of your templates.
また、テンプレート名をセットする際に拡張子を指定する必要はなくなりました。明示的に拡張子を指定していない場合は、レンダラーに応じたデフォルトの拡張子(.php .tpl など)がシステムによって自動的に付加されます。これは、国際化対応(i18n)を有効にしている場合に、システムが自動的にロケールに応じたテンプレートを探せるようにするためです。
For templates, it is now possible to have Agavi's objects (Response, Request, Controller and so on) auto-assigned to variables. Also, the name of the variable that contains the template attributes can be configured to be different from 'template', just like the variable that stores the output of slots (which now defaults to 'slots'). Optionally, the template variable array can be extracted, so the attributes become available as variables by their names.
テンプレートは自動的に変数に assign された Agavi のオブジェクト(Response, Request, Controller など)を持つことが可能になりました。また、テンプレート attribute を含む変数の名前は、従来の'template'から変更することができます。たとえば、スロットの出力が格納されている変数はデフォルトで'slot'です。
The current response instance is available by calling getResponse() on the current view. This way, you could insert content into the response and then not set a template to skip rendering and return content in a different form. Typical situations would be when you set PHP data into the response which gets encoded to XMLRPC, or where you encode PHP data to JSON that is then set in the response.
現在のレスポンスインスタンスを getRensponse() で取得することができます。この方法により、レスポンスに直接コンテンツを挿入することができます。すなわち、テンプレートをセットせずにレンダリングをスキップして、異なる形式でコンテンツを返すことができます。その典型的なシチューションは、XMLRPC にエンコードされるレスポンスに PHP データをセットしたり、JSON 形式にエンコードした PHP データをレスポンスにセットしたりする場合です。
Also, you can set a stream on a response, that stream will then be output using fpassthru() for better performance. This is perfect for serving binary content. Simply do $this->getResponse()->setContent(fopen('/path/to/image.png', 'rb')); or something equivalent to make this happen. Keep in mind that you should do this in a dedicated output type for this response type, which obviously also needs the respective headers (like Content-Type: image/png in this case).
レスポンスにはストリームをセットすることも可能です(このストリームはよりよいパフォーマンスのために fpassthru() によって出力されます)。これはバイナリコンテンツを出力するためにパーフェクトな方法です。$this->getResponse()->setContent(fopen('/path/to/image.png', 'rb')); またはこれと等価の何かを実行するだけです。ただし、このレスポンスタイプには専用の出力タイプを用いるべきであることに注意してください。このレスポンスタイプはそれぞれ個別のヘッダ(この例の場合は、Content-type: image/png)を必要とするためです。