MasterACE14 Posted July 4, 2011 Share Posted July 4, 2011 Good Day Developers, I've developed a template class which all works except for one part if done a certain way. Firstly here's the relevant code: public function display($page,$template,$content) { require_once( $this->hdr ); $template = self::gettemplate($page); // this way doesn't work # require_once(APPPATH.$_SESSION['cgs'].PATH_TEMPLATES . $page . '.php'); // this way does work echo self::parsetemplate($template,$content); require_once( $this->ftr ); } private function gettemplate($page) { // get the template $filename = APPPATH.$_SESSION['cgs'].PATH_TEMPLATES . $page . '.php'; if(file_exists($filename)) { require_once($filename); } else { die("Error: No Template Specified."); } return; } As you can see by the two comments in the first method. If I try and include that file using my second method( gettemplate() ) nothing is included, nor do I get a error. However if I just use require_once() on it's own and feed in the filepath it does work and includes the template? I'm at a total loss as to why my gettemplate() method isn't working? Any help is appreciated, Thanks. Regards, Ace Quote Link to comment https://forums.phpfreaks.com/topic/241029-2-ways-of-performing-task-1-works-and-the-other-wont/ Share on other sites More sharing options...
mikesta707 Posted July 4, 2011 Share Posted July 4, 2011 You seem to be accessing the function as if it were a static method when it is not Quote Link to comment https://forums.phpfreaks.com/topic/241029-2-ways-of-performing-task-1-works-and-the-other-wont/#findComment-1238048 Share on other sites More sharing options...
MasterACE14 Posted July 4, 2011 Author Share Posted July 4, 2011 public function display($page,$template,$content) { require_once( $this->hdr ); $template = $this->gettemplate($page); # require_once(APPPATH.$_SESSION['cgs'].PATH_TEMPLATES . $page . '.php'); echo $this->parsetemplate($template,$content); require_once( $this->ftr ); } still getting the same problem. :-/ Quote Link to comment https://forums.phpfreaks.com/topic/241029-2-ways-of-performing-task-1-works-and-the-other-wont/#findComment-1238059 Share on other sites More sharing options...
trq Posted July 4, 2011 Share Posted July 4, 2011 Calling require_once within a function will bring your template into that functions scope, you need to capture that and return it. This can be easily enough done using output buffering. Quote Link to comment https://forums.phpfreaks.com/topic/241029-2-ways-of-performing-task-1-works-and-the-other-wont/#findComment-1238121 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.