ブタさんとこのサンプルにあったようにMojavi + Smartyでcompileディレクトリを一個にしてると別モジュールの同名テンプレートを読み込んだ時にコンパイルされたファイル名がカブって動かない。(index.htmlとか)
Smartyのcompile_idにモジュール名を設定するさり気無い気配りを。

SmartyFilter.class.php:

<?php
require_once(RENDERER_DIR . "SmartyRenderer.class.php");

class SmartyFilter extends Filter {
    function execute (&$filterChain, &$controller, &$request, &$user) {
        // see if renderer is already loaded
        $loaded =& $request->getAttribute("SmartyRenderer");

        if ($loaded == NULL) {
            // smarty init params
            $params =  array(
                "cache_dir"      => SMARTY_CACHE_DIR,
                "caching"        => SMARTY_CACHING,
                "force_compile"  => SMARTY_FORCE_COMPILE,
                "compile_dir"    => SMARTY_COMPILE_DIR,
                "config_dir"     => $controller->getModuleDir()."config/",
                "app_name"       => $controller->getCurrentModule(),
                "debug_tpl"      => SMARTY_DEBUG_TPL,
                "debugging_ctrl" => SMARTY_DEBUGGING_CTRL,
                "debugging"      => SMARTY_DEBUGGING,
                <strong>"compile_id"     =&gt; $controller-&gt;currentModule</strong>
            );

            $renderer =& new SmartyRenderer($controller, $request, $user);
            $smarty = & $renderer-&gt;getEngine();

            foreach ( $params AS $key =&gt; $value ) {
                $smarty-&gt;$key = $value;
            }

            // set the renderer as a request attribute so we can retrieve it
            $request-&gt;setAttributeByRef("SmartyRenderer", $renderer);

            // execute chain
            $filterChain-&gt;execute($controller, $request, $user);

            // remove renderer
            $request-&gt;removeAttribute("SmartyRenderer");

        } else {
            $filterChain-&gt;execute($controller, $request, $user);
        }
    }
}
?&gt;

ref: Mojavi HTML_QuickForm Smarty + DB_DataObjectサンプル

Comments


Option