Zeradin Posted January 6, 2010 Share Posted January 6, 2010 When I first was learning php code on my own I figured to do it like this: each page would look like <?php include('header.php')?> <!-- where header had everything that was static on every page down to the container --> content of page <?php include('footer.php')?> <!-- the end of the page, close the header and footer --> I then took an internship and they taught me to do it this way: <html>...<body> <?php $page = $_GET['p']; if($page != NULL) { include($page.'.php'); } else { home page } </body></html> The latter way seems to be more widely used but I'm finding the first way is a lot easier. I run into problems titling pages the second way and a lot of other things that could be done much easier when using the first method. I've even started making mySQL entries for each page when I use the second way so I can grab a bunch of style variables out of the database from the page. I'm wondering what you use or recommend and what the advantages/disadvantages are that I'm not thinking about. Quote Link to comment https://forums.phpfreaks.com/topic/187436-dynamic-php-website-style/ Share on other sites More sharing options...
ignace Posted January 6, 2010 Share Posted January 6, 2010 The second method only works if rendering is done at the very last in your application. You could then for example create a head object that holds head information like meta, title, link, script, base, .. $head->setTitle('Title Here'); Or you could use something like Smarty but instead of using Smarty directly modify it your needs: $smarty->setTitle('Title Here'); $smarty->addMeta(..); $smarty->addScript(..); There are many ways you can go about it what also makes it so easy/hard to develop an application because you have so many possibilities and you can not just select just one without experiencing the (dis-)advantages of it first. My best advice would be experiment try things see what works for you. If something gives you trouble or something takes more work then actually should be required try to solve it in the most simplest manner. Quote Link to comment https://forums.phpfreaks.com/topic/187436-dynamic-php-website-style/#findComment-989892 Share on other sites More sharing options...
Zeradin Posted January 6, 2010 Author Share Posted January 6, 2010 The second method only works if rendering is done at the very last in your application. You could then for example create a head object that holds head information like meta, title, link, script, base, .. $head->setTitle('Title Here'); Or you could use something like Smarty but instead of using Smarty directly modify it your needs: $smarty->setTitle('Title Here'); $smarty->addMeta(..); $smarty->addScript(..); There are many ways you can go about it what also makes it so easy/hard to develop an application because you have so many possibilities and you can not just select just one without experiencing the (dis-)advantages of it first. My best advice would be experiment try things see what works for you. If something gives you trouble or something takes more work then actually should be required try to solve it in the most simplest manner. What do you mean if the rendering is done last? I mean... I guess I know what you mean, but how is this accomplished? Can you point me in the right direction? Quote Link to comment https://forums.phpfreaks.com/topic/187436-dynamic-php-website-style/#findComment-989951 Share on other sites More sharing options...
ignace Posted January 6, 2010 Share Posted January 6, 2010 Well your first approach load the header.php file which lead to the title and meta information already sent to the browser. Your second approach is more dynamic but still does not allow you to modify title nor meta information. The only way for you to maintain the possibility for modification is to keep your html file from being sent to the browser you can for example create an object (DOMDocument, Smarty, ..) that will hold your entire website layout until you believe you are completly done and ready to sent it to the browser. This approach allows you to modify everything until it is sent to the browser. You can even cancel the processing and start a new one by redirecting the user to another section of your website. Quote Link to comment https://forums.phpfreaks.com/topic/187436-dynamic-php-website-style/#findComment-989982 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.