肉とビールとパンケーキ by @sotarok

少し大人になった「肉とご飯と甘いもの」

Ethna-2.3.2で変更されたEthna_Renderer_Smartyについて

Ethna-2.3.2の変更点について、

  • Ethna_Renderer, Ethna_Renderer_Smarty
    • perform() の第2引数に $capture フラグを追加
    • true のときは Smarty 的に display でなく fetch になります。
404 Not Found - Ethna

とありました。
お?こないだからxoops風だのRailsライクだのって騒いでた方法が、できるようになるのかなー?と思いつつ、ちょいちょいソース眺めてみました。(ref.Ethnaでxoopsみたいなテンプレートの使い方をする:ビュー内でテーマ変更 - 肉とご飯と甘いもの @ sotarok


あ、あった、これですね。

<?php
...

    function perform($template = null, $capture = false)
    {
        if ($template === null && $this->template === null) {
            return Ethna::raiseWarning('template is not defined');
        }

        if ($template !== null) {
            $this->template = $template;
        }

        // ココから変更点
        if ((is_absolute_path($this->template) && is_readable($this->template))
            || is_readable($this->template_dir . $this->template)) {
                if ($capture === true) {
                    $captured = $this->engine->fetch($this->template);
                    return $captured;
                } else {
                    $this->engine->display($this->template);
                }
        } else {
            return Ethna::raiseWarning('template not found ' . $this->template);
        }
    }
...

ほお〜〜
なるほどね〜
フェッチして返してくるのね。これをアサインしてやったりすればいいわけだ。

で、Viewはどうなってるかというと・・・

<?php
...
    function forward()
    {
        $renderer =& $this->_getRenderer();
        $this->_setDefault($renderer);
        $renderer->perform($this->forward_path);
    }
...

・・・あれ?
perform() の結果って受け取ってないのか・・・?これだとRendererでいくら結果返してきても・・・。第二引数も設定してないしな。てか第二引数ってどこで使うんだ?こってなに、「ViewClassをオーバーライドして自分でカスタマイズして使ってね♪」っていうのが前提なのかな?
そもそもこの $capture って何に使う用だ?お〜全然わかりません(笑)

えーっと、Viewからフェッチ結果が返ってきて嬉しい場面ていつだ?あるViewやActionから、ほかのViewを呼び出して使いたいとき?


追記

ホントすいません。MLで聞いたら、MailSenderで使われてました。
なんかもー的外れなことをもんもんと考えてしまっていましたorz