Skip to content

Instantly share code, notes, and snippets.

@madr
Created April 30, 2015 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madr/f94d26209cc01bbe824b to your computer and use it in GitHub Desktop.
Save madr/f94d26209cc01bbe824b to your computer and use it in GitHub Desktop.
view.php
<?php
/**
* view.php
*
* simple view class, template-based.
* @todo indent markup using tidy?
*
* $Rev$
* $Author$
* $Date$
*/
class view
{
protected $hasLayout;
private $file;
public function __construct( $file_path ) {
if(!file_exists($file_path)) {
throw new Exception('file ' . $file_path . ' does not exist!', 666);
} else {
$this->file = $file_path;
}
}
/**
* Compile the view
*
* @return $HTMLSource the compiled view
*/
public function compile($registry = false) {
if($registry === false){
$registry =& registry::getInstance();
}
$user =& user::getInstance();
foreach($registry as $k=>$v){
$$k = $v;
}
ob_start();
require $this->file;
$body = ob_get_clean();
(isset($contentType)) ? http_response::content($contentType) : http_response::content(CONTENT_TYPE);
$isFragment = isset($this->isFragment);
if(defined('LAYOUT') && !$isFragment){
ob_start();
require LAYOUT;
$body = ob_get_clean();
}
return $body;
}
public function isFragment() {
$this->isFragment = true;
}
function __toString() {
return __CLASS__;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment