Created
May 18, 2015 11:40
-
-
Save jawdatls/3117a16dba535116516d to your computer and use it in GitHub Desktop.
Simple page render and redirect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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