FuelPHPのテンプレートコントローラでPC/スマホの出しわけ

FuelPHPでテンプレートコントローラを使用している場合に、PCとスマホでビューを出し分ける方法を検討。

ベースとなるテンプレートは

  • スマホ : views/template_sp.php
  • スマホ以外 : views/template.php

スマホからアクセスされた場合、parent::before()を実行する前に、$templateを上書きする。

<?php

class Controller_Blog extends Controller_Template
{
    public function before()
    {
        if (Agent::is_smartphone()) {
            $this->template = 'template_sp';
        }
        parent::before();
    }

    public function action_index()
    {
        $view = View::forge('pc/blog/index');
        if (Agent::is_smartphone()) {
            $view = View::forge('mb/blog/index');
        }
        $this->template->title = 'Blog &raquo; index';
        $this->template->content = $view;
    }
}

UAでのスマホ判定はこちら

上記の場合、ファイル名やパスの修正が入った場合、コツコツ修正する必要がある為、無理があるか。。。