Nolongerused3921 Posted January 27, 2007 Share Posted January 27, 2007 Well I ditched my idea to load, store, and eval() templates from files as it has some [b]serious[/b] security issues, and decided to go with a much simpler approach:[code]class template { public $theme = "default"; public $theme_dir = "themes/"; private $templates = array(); private $vars = array(); private $errors = array(); private $cwd = ""; function template() { $this->cwd = getcwd(); } function assign($var_name, $var_value) { if (!get_magic_quotes_gpc()) { $var_value = addslashes(&$var_value); } $var_value = str_replace(";","",$var_value); $var_value = preg_replace("/[^A-Za-z0-9_-]\n\t\r/","",$var_value); $this->vars[$var_name] = $var_value; } function display($file) { //chdir("../".$this->theme_dir); //Takes about 20 milliseconds to chdir $filename = $this->theme_dir.$this->theme."/".$file.".tpl.php"; //Add "../". to test locally extract($this->vars); ob_start(); include($filename); $contents = ob_get_contents(); ob_end_clean(); print $contents; return 1; }}[/code]However, I'm having some troubles... How can I access functions from this class inside my templates? I obviously can't extract() the class itself seeing as its not an array... And I can't exactly use $this-> or $template, seeing as ... Well, I honestly have no idea why I can't do this.So whats a solution? What about accessing other classes? What about accessing [b]just[/b] a function, completely outside of a class? Quote Link to comment Share on other sites More sharing options...
Braclayrab Posted January 27, 2007 Share Posted January 27, 2007 I'm not understanding what you are trying to do... why are you doing this? Will making the methods static help? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.