Advertisement
Guest User

Untitled

a guest
Jul 26th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Framework;
  4.  
  5. class View {
  6.  
  7. private $variable = array();
  8. private $title = 'Example title';
  9. private $CurrentBlock = '';
  10. private $blocks = array();
  11. private $fileExtend = false;
  12.  
  13. public function set($key, $value) {
  14. $this->variable[$key] = $value;
  15. }
  16.  
  17. public function get($key) {
  18. return isset($this->variable[$key]) ? $this->variable[$key] : '';
  19. }
  20.  
  21. public function display($file) {
  22. $this->load($file);
  23. if($this->fileExtend)
  24. $this->load($this->fileExtend);
  25. }
  26.  
  27. public function load($file) {
  28. $template = $file;
  29. $file = ROOT_PATH.APP.'/View/'.$file.'.php';
  30. if(file_exists($file))
  31. include($file);
  32. else
  33. echo 'Template "'.$template.'" does not exist!<br />';
  34. }
  35.  
  36. public function setTitle($title) {
  37. $this->title = $title;
  38. }
  39.  
  40. public function getTitle() {
  41. return $this->title;
  42. }
  43.  
  44. public function startBlock($name) {
  45. $this->CurrentBlock = $name;
  46. ob_start();
  47. }
  48.  
  49. public function stopBlock() {
  50. $this->blocks[$this->CurrentBlock] = ob_get_clean();
  51. $this->CurrentBlock = NULL;
  52. }
  53.  
  54. public function getBlock($name) {
  55. return isset($this->blocks[$name]) ? $this->blocks[$name] : '';
  56. }
  57.  
  58. public function extend($file) {
  59. $name = $file;
  60. $file = ROOT_PATH.APP.'/View/'.$file.'.php';
  61. if(file_exists($file))
  62. $this->fileExtend = $name;
  63. else{
  64. echo 'Layout "'.$template.'" does not exist!<br />';
  65. }
  66. }
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement