cgm225 Posted April 13, 2008 Share Posted April 13, 2008 I have a page I am included right now as such: include PAGE_DIR . "/" . $this->getName() . "/" . $action . "View.php5"; However, I want to make a variable in my class called $this->content hold the contents of the file above so that I can echo the file contents like so: echo $this->content; Restated, how can I make $this->content = the contents of PAGE_DIR . "/" . $this->getName() . "/" . $action . "View.php5" Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/100922-setting-the-value-of-a-variable-to-the-content-of-file/ Share on other sites More sharing options...
trq Posted April 13, 2008 Share Posted April 13, 2008 <?php $this->content = file_get_contents(PAGE_DIR . "/" . $this->getName() . "/" . $action . "View.php5"); ?> Link to comment https://forums.phpfreaks.com/topic/100922-setting-the-value-of-a-variable-to-the-content-of-file/#findComment-516108 Share on other sites More sharing options...
trq Posted April 13, 2008 Share Posted April 13, 2008 Actually, if your view contains php which needs to be parsed (which it likely does) you would need to use output buffering. <?php function getview($path) { ob_start(); include $path; $ret = ob_get_contents(); ob_end_clean(); return $ret; } ?> Link to comment https://forums.phpfreaks.com/topic/100922-setting-the-value-of-a-variable-to-the-content-of-file/#findComment-516115 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.