Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Framework;
- class View {
- private $variable = array();
- private $title = 'Example title';
- private $CurrentBlock = '';
- private $blocks = array();
- private $fileExtend = false;
- public function set($key, $value) {
- $this->variable[$key] = $value;
- }
- public function get($key) {
- return isset($this->variable[$key]) ? $this->variable[$key] : '';
- }
- public function display($file) {
- $this->load($file);
- if($this->fileExtend)
- $this->load($this->fileExtend);
- }
- public function load($file) {
- $template = $file;
- $file = ROOT_PATH.APP.'/View/'.$file.'.php';
- if(file_exists($file))
- include($file);
- else
- echo 'Template "'.$template.'" does not exist!<br />';
- }
- public function setTitle($title) {
- $this->title = $title;
- }
- public function getTitle() {
- return $this->title;
- }
- public function startBlock($name) {
- $this->CurrentBlock = $name;
- ob_start();
- }
- public function stopBlock() {
- $this->blocks[$this->CurrentBlock] = ob_get_clean();
- $this->CurrentBlock = NULL;
- }
- public function getBlock($name) {
- return isset($this->blocks[$name]) ? $this->blocks[$name] : '';
- }
- public function extend($file) {
- $name = $file;
- $file = ROOT_PATH.APP.'/View/'.$file.'.php';
- if(file_exists($file))
- $this->fileExtend = $name;
- else{
- echo 'Layout "'.$template.'" does not exist!<br />';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement