Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class SnapController {
- var $action;
- function __construct($action) {
- $this->action = $action;
- return $this->$action();
- }
- function __set($k, $v) {
- $this->tmpl_vars[$k] = $v;
- }
- }
- class SnapView {
- var $views_dir;
- var $folder;
- var $file;
- var $path;
- var $tmpl_vars;
- function __construct(SnapController $c) {
- $this->views_dir = $_SERVER['DOCUMENT_ROOT'] . "/views";
- $this->folder = str_replace("controller", "", (strtolower(get_class($c))));
- $this->file = $c->action . ".tpl.php";
- $this->path = $this->views_dir . "/" . $this->folder . "/" . $this->file;
- foreach($c->tmpl_vars as $k => $v) {
- $this->tmpl_vars[$k] = $v;
- }
- include($this->path);
- }
- function __get($k) {
- return $this->tmpl_vars[$k];
- }
- function __set($k, $v) {
- $this->tmpl_vars[$k] = $v;
- }
- }
- ?>
- ## Usage
- <?php
- class SnapEd4MeController extends SnapController {
- function index() {
- $page = new SnapPage(array("id" => 1));
- $this->page = $page;
- }
- }
- $c = new SnapEd4MeController("index");
- new SnapView($c);
Add Comment
Please, Sign In to add comment