Location: PHPKode > scripts > PHP-Loader > view/HTMLView.class.php
<?php
/**
 * HTMLView.class.php
 *
 * Subclass for the PhritzTpl class. Sets the template directory to the HTML
 * folder, formats the response and displays the result
 *
 * LICENSE: This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * @package Phritz
 * @link http://phritz.fritz-works.com
 * @author Michael Collado <hide@address.com>
 * @copyright 2006
 * @version 0.0.1a
 **/
require_once 'PhritzTpl.class.php';

class HTMLView extends PhritzTpl implements PhritzViewInterface {
    
    public function __construct() {
        parent::__construct();
        parent::setThemePath('templates'.DIR_SEP.'html'.DIR_SEP.'default');
    }
    
    public function setThemePath($dir) {
        return parent::setThemePath('templates'.DIR_SEP.'html'.DIR_SEP.$dir);
    }

    public function formatResponse($request, $response) {
        $dbg = Phritz::getDebugger();

        //Was an exception passed to the View for display?
        if ($response instanceof PhritzException) {
            $this->assign('FAULT', 1);
            $this->assign('ERROR', array('CODE'=>$response->getCode(),
                                    'MESSAGE'=>$response->getMessage()));
            $content = $this->fetch('error.tpl');
            $this->assign('CONTENT', $content);
            $this->clear_assign('ERROR');
         } else {
            $this->assign('RESPONSE', $response->toArray());
            /*If we have a template associated with the content,
              pull that template and assign it to the CONTENT node*/
            $t = $response->getTemplate();
            try {
                if ($t != '') {
                    $content = $this->fetch($t);
                    $this->assign('CONTENT', $content);
                }
            } catch (Exception $e) {
                switch(get_class($e)) {
                    case 'PhritzParseException':
                        $dbg_line = "Callback function for template $t processing failed: ";
                        break;
                    case 'PhritzFileException':
                        $dbg_line = "File error for template $t processing: ";
                        break;
                    case 'DOMException':
                        $dbg_line = "DOM exception thrown for template $t processing. Check xml syntax: ";
                        break;
                    default:
                        $dbg_line = "Unknown exception thrown for template $t processing. ";
                        break;
                }
                error_log($dbg_line.$e->getMessage());
                Phritz::debug($dbg_line.$e->getMessage(), $e->getFile(), $e->getLine());
                $this->assign('FAULT', 1);
                $this->assign('ERROR', array('CODE'=>$e->getCode(),
                                    'MESSAGE'=>$e->getMessage()));
                $content = $this->fetch('error.tpl');
                $this->assign('CONTENT', $content);
                $this->clear_assign('ERROR');
            }

            $this->clear_assign('RESPONSE');
       }
        return true;
    }

    public function display($tpl = 'index.tpl', $cacheid = null) {
        header('Content-Type: text/html');
        $conf = Phritz::getConfig();
        $themepath = $conf['DefaultTheme'];
        echo $this->fetch(PHRITZ_ROOT.'/themes/html/'.$themepath.'/index.tpl');
    }
}
?>
Return current item: PHP-Loader