【FuelPHP】Controller_Template クラスを使ったサンプル
どうも。
ブログのトップでスクロールするのも煩わしいと思ったので、日記以外の記事は「続きを読む」機能を使う。
今回は Controller_Template クラスを使ったときのメモ。
使用するディレクトリ構造
/usr/share/nginx/html/fuelphp/ └── fuel └── app ├── classes │ └── controller │ └── sample.php ├── config │ └── routes.php └── views └── sample └── index.php
(なーんか表示がズレてる感じがするんだよねぇ・・・)
テンプレートの作成
- /usr/share/nginx/html/fuelphp/fuel/app/views/template.php
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>サンプル</title> <?php echo Asset::css('bootstrap.css'); ?> <?php echo Asset::css('fuelphp.css'); ?> </head> <body> <div id="header"> <div class="row"> <div id="logo"></div> </div> </div> <div class="container"> <?php echo $content; ?> <hr/> <footer> <p class="pull-right">Page rendered in {exec_time}s using {mem_usage}mb of memory.</p> <p> <a href="http://fuelphp.com">FuelPHP</a> is released under the MIT license.<br> <small>Version: <?php echo Fuel::VERSION; ?></small> </p> </footer> </div> </body> </html>
このようにファイル名 template.php で作成すると、デフォルトで読み込んでくれる。
コントローラの作成
- /usr/share/nginx/html/fuelphp/fuel/app/classes/controller/sample.php
<?php class Controller_Sample extends Controller_Template { public function action_index() { $this->template->content = View::forge('sample/index'); $this->template->content->set('hoge', 'サンプル'); } }