Skip to content

Instantly share code, notes, and snippets.

@Khanashima
Created April 21, 2014 14:25
Show Gist options
  • Save Khanashima/11144257 to your computer and use it in GitHub Desktop.
Save Khanashima/11144257 to your computer and use it in GitHub Desktop.
viewの共通テンプレートを作成する ref: http://qiita.com/kiimiiis/items/a015399455ef9c0f1659
class Controller_Base extends Controller_Template
{
public function before()
{
parent::before();
//header.phpをテンプレートの$headerとbindさせる。
$this->template->header = View::forge('parts/header');
//footer.phpをテンプレートの$footerとbindさせる。
$this->template->footer = View::forge('parts/footer');
}
public function after($response)
{
$response = parent::after($response); // あなた自身のレスポンスオブジェクトを作成する場合は必要ありません。
return $response; // after() は確実に Response オブジェクトを返すように
}
}
class Controller_Hello extends Controller_Base
{
public function action_index()
{
//template.phpのcontentとアクション毎のviewをbindさせる
$this->template->content = View::forge('hello/index');
//デフォルト設定を変えず、template.phpのファイル名を変更しない場合はtemplateのviewオブジェクトを返す
}
}
<div>
コンテンツ領域です
</div>
<div>
<?php echo HEADER; ?>
</div>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<header>
<!-- header.phpファイルを読み込む-->
<?php echo $header; ?>
</header>
<div id="content">
<!-- 各アクションの内容を読み込む-->
<?php echo $content; ?>
</div>
<footer>
<!-- footer.phpファイルを読み込む-->
<?php echo $footer; ?>
</footer>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<header>
<!-- header.phpファイルを読み込む-->
<div>
    ここはheaderの領域です
     </div>
</header>
<div id="content">
<!-- 各アクションの内容を読み込む-->
   <div>
   コンテンツ領域です
    </div>
</div>
<footer>
<!-- footer.phpファイルを読み込む-->
<div>
   ここはfooterの領域です
    </div>
</footer>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment