fersick Posted March 22, 2013 Share Posted March 22, 2013 I have been working through the text book. Practical PHP by Paul Hudson. The chapter on creating a simple OOP site. wont render in a browser. I have written the code out get not errors in the debugging console i see my rendered HTML code in the console. But in a browser i get code setPage($page); $content = <<setContent($content); $site->render(); ?> These are the files i have written index.php <?php include 'stdlib.php'; error_reporting(E_ALL); ini_set('display_errors', 1); $site = new csite(); // This is a function specific to this site! initialise_site($site); $page = new cpage("Welcome to my site!"); $site->setPage($page); $content = <<<EOT Welcome to my personal web site! EOT; $page->setContent($content); $site->render(); ?> I feel it has something to do with the EOT reference, as the code surrounding the EOT is what is outputted in browser. stlib.php <?php function __autoload($class) { include "$class.php"; } function initialise_site(csite $site) { $site -> addHeader("header.php"); $site -> addFooter("footer.php"); } ?> csite.php <?php class csite { private $headers; private $footers; private $page; public function __construct() { $this -> headers = array(); $this -> footers = array(); } public function __destruct() { // clean up here. } public function render() { foreach ($this->headers as $header) { include $header; } $this->page->render(); foreach ($this->footers as $footer) { include $footer; } } public function addHeader($file) { $this -> headers[] = $file; } public function addFooter($file) { $this -> footers[] = $file; } public function setPage(cpage $page) { $this -> page = $page; } } ?> cpage.php <?php class cpage { private $title; private $constant; public function __construct($title) { $this -> title = $title; } public function __destruct() { // clean up here } public function render() { echo "<H1>{$this->title}</H1>"; echo $this -> content; } public function setContent($content) { $this -> content = $content; } } ?> header.php and footer.php are just basic HTML code. Quote Link to comment https://forums.phpfreaks.com/topic/275996-practical-php-simple-oop-site-wont-render-in-browser/ Share on other sites More sharing options...
requinix Posted March 22, 2013 Share Posted March 22, 2013 Seems like you don't have PHP installed. Are you making sure to run the file through a web server? Your browser should not have anything like "file://" in the address bar but look like a normal URL. Quote Link to comment https://forums.phpfreaks.com/topic/275996-practical-php-simple-oop-site-wont-render-in-browser/#findComment-1420256 Share on other sites More sharing options...
fersick Posted March 22, 2013 Author Share Posted March 22, 2013 I'm running code from my htdoc folder in xampp using localhost or 127.0.0.1 Quote Link to comment https://forums.phpfreaks.com/topic/275996-practical-php-simple-oop-site-wont-render-in-browser/#findComment-1420265 Share on other sites More sharing options...
requinix Posted March 22, 2013 Share Posted March 22, 2013 Do a View Source of the page. See your PHP code? That means PHP isn't running your script. Are you using a .php file extension? Quote Link to comment https://forums.phpfreaks.com/topic/275996-practical-php-simple-oop-site-wont-render-in-browser/#findComment-1420267 Share on other sites More sharing options...
fersick Posted March 22, 2013 Author Share Posted March 22, 2013 All files have .PHP as the extention. I'm on my phone qtm. Will check the source code tomorrow when I'm at my pc Quote Link to comment https://forums.phpfreaks.com/topic/275996-practical-php-simple-oop-site-wont-render-in-browser/#findComment-1420271 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.