It doesn't matter if you do all the error checking in the world, or if you have the most beautiful graphics, if your site or application design isn't usable, it's not going to do well. Get input and advice on usability and user interface issues here.
Hello everyone. I am a not quite a nocie to PHP, but a novice to design with PHP, so I have the following question:
How do I make a site's design using PHP (I wish to have a navigational bar at the top, bottom, and side [slightly different, but nevertheless]). And I do not want this to change - only the middle part (where I will place the corresponding texts/chrats/pics/setc.
How exactly do i do that? I have been told to use 'incclude', but something seems wring with that.
You make your site template using html/xhtml/css etc and then where you want the main content to change on each page include the required page like so:
And when the user clicks that it will show your template plus th content of: "some/path/to/files/contact.php". You should of course check the value in the url so that people dont traverse the directories and read files there not ment to.
<?php
// Initializing variables
$this_page = 'index.php';
$page_title = 'Page Title';
include 'page_open.php'; // Opens <html>,
// declares <title> = $page_title;</title>,
// and stops after opening <body> tag.
include 'top_nav.php'; // Includes top navigation <div>.
include 'left_nav.php'; // Includes left navigation <div>.
include $this_page; // Includes and displays $this_page content <div>.
include 'bottom_nav.php'; // Includes bottom navigation div.
include 'page_close.php'; // Closes </body> and </html>.
?>
How you pass the $this_page, $page_title, etc., variables is a matter of preference and need. In this case I coded them into the page because I generally do not like to allow the user inside the script any more than absolutely necessary. I can easily enough change my mind about that in the future since the $this_page (etc.) variables are already in the architecture.
P.S. I really like that $safe_files array technique, LiLpunkSkateR. (Got the author wrong on my first pass, sorry.)
Last edited by lolpix on Sat Jul 17, 2004 12:35 pm, edited 1 time in total.
That works nicely as well. The only thing I do not like about it is the use of a big table to lay out the page. I am trying to move towards formatting layout using CSS as much as possible. However, that is my own pet idea, and tables have worked well for formatting pages for a long time.
I also think it would be better to have a nav class with subclasses top_nav, left_nav, and bottom_nav which extend nav. That way you could format their display a little differently but maintiaining the links themselves can be handled in the superclass for better integrity.
Oh, I didn't mean to use tables really, it was just to show layout. I use divs for layout in my pages, but that is all code i typed up in 2 minutes.
The HTML can be whatever you want, thats the point, but now you have variables to work with (ie. {content}).
Think we maybe going slightly over the top if Yanger is only new to php though Although by all means try and use these more complicated methods as you will learn more and probably have a slightly better system in the end.
It would be a little more complex, but I was wondering what disadvantages and advantages there would be to haveing as much of the page as possible included.
Ex: All of your header is in one file down to the point of the actual content that is going to be vastly different. Then At the end there would be another include with all the code until the end of the <html> tag. Then the first of your page would just be setting variables that would be used in the page, probably as part of a page object.
<?php
// Set Page Variables <--- also get from different sources
$page_title = "An Exciting Page";
$page_selected = "home";
// etc.. other page variables that you feel are important that change and aren't a neccesarily part of your content.
require("header.php");
// Do all your design of the page content here
// This is where all of your indivual page design comes in, the rest is the usual standard stuff.
require("footer.php");
?>
It seems that this would make it so that you when you want to change things on your header and footer all the code is in the two files so you don't have to change a lot of the individual pages later.
Are there some major flaws to this UI design or is that pretty much what you were saying only in different words that make sense only to me?
edit: I guess that this is pretty much what lolpix was saying, sorry for the repetition.