jayla Posted August 21, 2008 Share Posted August 21, 2008 Hi Guys I did some basic PHP at university, but that was some time ago, and I've taken it upon myself to create a new website for my company, and hence want another stab at PHP for this, I have a few questions and hoping some of you guys can point me in the write direction. 1. Directory structure, With Java I'd use the standard WEB-INF folder, resources, main, java, help etc directory structure. Great, but not really useful for a PHP site. Is there a general "standard" of how you should arrange files? I've had a look on google and have seen some peoples approach to this, but I'm not really sure of which one to follow! 2. Content, includes, hardcoded or database? I'll have various pages on this website, all will look the same pretty much apart from the actual content, being everything between the header, footer, and side-navbar. Should I just make exact copies of 1 page throughout my site, and just hardcode the content? Or, would it be best to have the page, "products.php" for example, and then have an include to include a file called "products_bodytext.php"? Thirdly, would it be a good idea to populate the body text from a database? I will probably have around 20 pages to start with, but potential for more, so would prefer the best approach that makes it easier/quick to add further pages in the future 3. Site-Root, I have a lot of anchors, includes, img tags etc that use "../../somedirectory/file.php" or "../../../file.php", all of the "../" is quite confusing, and when I shift files around I have the lovely task of going back and fixing them all. Is there a way of declaring a "site root" for example, so I could say "<SITEROOT>/css/main.css"? Really appreciate any advice you can give, I'm looking forward to getting stuck into some PHP over the weekend! (gahh...geek ) Thanks Link to comment https://forums.phpfreaks.com/topic/120765-advice-for-a-newbie/ Share on other sites More sharing options...
akitchin Posted August 21, 2008 Share Posted August 21, 2008 1. there's no set precedent. go with what you like, what works well, and what you understand. it shouldn't be hard to come up with something you like that makes semantic sense to an outsider. 2. generally, i would reserve dynamic content for the database. that is, content that is likely to change often and at the hands of someone without access (or savvy) to manipulate the files themselves; for example, a site-owner who wants to put news up uses a control panel which adjusts the db. i see no reason why static content should be stored elsewhere than on the page itself. i would actually suggest that the inverse of your idea would be best. a new page for each static content that's relevant (ie. products vs. about us sort of thing), in which you'll include the common header, spit out static content, and then include the footer. this allows you to quickly construct new pages by copying/pasting the generic structure and adjusting the content to match. NOTE: some will disagree with me on the above, and suggest you make a master page that filters a URL request and spits out the appropriate data for the page they want. the only reason i advise against this is it induces a number of errors and sloppiness if you're new to the game (or rusty ) and it also quickly becomes unmanageable if you have many pages. i prefer to know exactly which file to look in to adjust a spelling mistake, or which page to edit if i suddenly want to add some server-side functionality like echoing the current date and time. mostly a matter of what you're comfortable with. i just think a lot of people unnecessarily rush towards making a master page when several different files will do just fine. 3. you can define any constants you want within PHP and use them at will. this is done using the define() function: <?php define('SITE_ROOT', '/this_subdirectory/development_site/'); ?> i haven't always had the most luck with this, since apparently windows and *nix boxes treat that beginning slash differently, but it's worth a shot. Link to comment https://forums.phpfreaks.com/topic/120765-advice-for-a-newbie/#findComment-622468 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.