Skip to content

Instantly share code, notes, and snippets.

@jawdatls
Created May 18, 2015 11:40
Show Gist options
  • Select an option

  • Save jawdatls/3117a16dba535116516d to your computer and use it in GitHub Desktop.

Select an option

Save jawdatls/3117a16dba535116516d to your computer and use it in GitHub Desktop.
Simple page render and redirect
<?php
class Page{
public $name;
public $params;
public $title;
public $content;
public function __construct($name,$params = array()){
$this->name = $name;
$this->params = $params;
$this->title = '';
}
public function render(){
ob_start();
extract($this->params);
include('./pages/'.$this->name.'/index.php');
$this->content = ob_get_clean();
}
private static $_PAGE = null;
public static function load(){
if(self::$_PAGE == null){
$name = 'default';
$params = array_merge($_GET,$_POST);
if(isset($params['n'])){
$name = $params['n'];
unset($params['n']);
}
self::$_PAGE = new self($name,$params);
self::$_PAGE->render();
}
return self::$_PAGE;
}
public static function redirect($name){
header('location:index.php?n='.$name);
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment