Viewクラス

Controllerクラス内でインスタンス生成され、そのインスタンスはActionクラスのクラス変数として保持されます。テンプレート処理に関してはSmarty-Lightを使用します。

class View {

  var $_template;
  var $_items;
  var $_actionName;

  function View($actionName) {

    $configs = Session::get(SESSION_KEY_CONFIG);

    $this->_template =& new template();
    $this->_template->template_dir = APP_HOME . $configs[KEY_TEMPLATE_DIR];
    $this->_template->compile_dir = APP_HOME . $configs[KEY_TEMPLATE_C_DIR];

    $this->_items = array();
    $this->_actionName = $actionName;
  }

  function addItem($key, $value) {
    $this->_items[$key] = $value;
  }

  function forward($name = NULL) {
     if (is_null($name)) {
       $this->_display($this->_actionName . '.tpl');
     }
     $this->_display($name . '.tpl');
  }

  function _display($template) {
    foreach ($this->_items as $key => $value) {
      $this->_template->assign($key, $value);
    }
    $this->_template->display($template);
  }
}