Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

An easy view class to use in WordPress plugins

View MyView.class.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
<?php
class My_View {
/**
* Path of the view to render
*/
var $view = "";
/**
* Variables for the view
*/
var $vars = array();
/**
* Construct a view from a file in the
*/
public function __construct($view) {
if (file_exists(MY_PLUGIN_ABS_PATH."/views/".$view.".view.php")) {
$this->view = MY_PLUGIN_ABS_PATH."/views/".$view.".view.php";
} else {
wp_die(__("View ".SPT_PLUGIN_ABS_PATH."/views/".$view.".view.php"." not found"));
}
}
/**
* set a variable which gets rendered in the view
*/
public function set($name,$value) {
$this->vars[$name] = $value;
}
/**
* render the view
*/
public function render() {
extract($this->vars,EXTR_SKIP);
ob_start();
include $this->view;
echo ob_get_clean();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.