Ethna_Renderer_PHP.php
最近 普通のPHPファイルをテンプレートにしてるのでEthnaでも欲しかったので作ってみた。
ただ Ethna_Rendererを継承してperformの内容をちょっと変えただけ。
<?php
require_once "Ethna/class/Ethna_SmartyPlugin.php";
class Ethna_Renderer_PHP extends Ethna_Renderer
{
function perform ($template = null)
{
if ($template == null && $this->template == null) {
return Ethna::raiseWarning('template is not defined');
}
if ($template != null) {
$this->template = $template;
}
// テンプレートの有無のチェック
if (is_readable($this->template_dir . $this->template)) {
$output = $this->_render($this->template_dir.$this->template, $this->prop);
echo $output;
} else {
return Ethna::raiseWarning("template is not found: " . $this->template);
}
}
function _render ($_template, $_prop)
{
ob_start();
ob_implicit_flush(0);
extract($_prop);
require($_template);
return ob_get_clean();
}
function input ($name, $params = array())
{
$params["name"] = $name;
$smarty = null;
return smarty_function_form_input($params, $smarty);
}
}
テンプレートでは以下のような感じで $app $app_ne $config などにアクセスできます。
<html> <h1><?php echo $app["title"] ?></h1> <p> <?php echo $app_ne["contents"] ?> </p> <a href="<?php echo $config["url"] ?>">index</a> </html>Smartyのform_imput を使うには
<?php echo $this->input("email") ?>
みたいな感じ。超やっつけ仕事だけど。
コメントする