Guest User

Untitled

a guest
Jan 5th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. <?php
  2. class SnapController {
  3. var $action;
  4.  
  5. function __construct($action) {
  6. $this->action = $action;
  7. return $this->$action();
  8. }
  9.  
  10. function __set($k, $v) {
  11. $this->tmpl_vars[$k] = $v;
  12. }
  13. }
  14.  
  15. class SnapView {
  16. var $views_dir;
  17. var $folder;
  18. var $file;
  19. var $path;
  20. var $tmpl_vars;
  21.  
  22. function __construct(SnapController $c) {
  23. $this->views_dir = $_SERVER['DOCUMENT_ROOT'] . "/views";
  24. $this->folder = str_replace("controller", "", (strtolower(get_class($c))));
  25. $this->file = $c->action . ".tpl.php";
  26. $this->path = $this->views_dir . "/" . $this->folder . "/" . $this->file;
  27.  
  28. foreach($c->tmpl_vars as $k => $v) {
  29. $this->tmpl_vars[$k] = $v;
  30. }
  31.  
  32. include($this->path);
  33. }
  34.  
  35. function __get($k) {
  36. return $this->tmpl_vars[$k];
  37. }
  38.  
  39. function __set($k, $v) {
  40. $this->tmpl_vars[$k] = $v;
  41. }
  42. }
  43.  
  44. ?>
  45.  
  46. ## Usage
  47.  
  48. <?php
  49.  
  50. class SnapEd4MeController extends SnapController {
  51. function index() {
  52. $page = new SnapPage(array("id" => 1));
  53. $this->page = $page;
  54. }
  55. }
  56.  
  57. $c = new SnapEd4MeController("index");
  58. new SnapView($c);
Add Comment
Please, Sign In to add comment