Jump to content

Server-side page indicator


kurt.santo

Recommended Posts

Thats pretty good advice for usability. I assume you're talking about the links that make up a sites navigation and so are on every page. You could write a little function which you call for each navigation link, passing in the link location and the link text. The function would then need to check the current page's path obtainable with $_SERVER['PHP_SELF'] to the path received as a parameter. Depending on the result you either output an <a> or a <strong>.Thats the nicest way I can think of off hand. Hope that helps a little.

Link to comment
Share on other sites

Thats pretty good advice for usability. I assume you're talking about the links that make up a sites navigation and so are on every page. You could write a little function which you call for each navigation link, passing in the link location and the link text. The function would then need to check the current page's path obtainable with $_SERVER['PHP_SELF'] to the path received as a parameter. Depending on the result you either output an <a> or a <strong>.Thats the nicest way I can think of off hand. Hope that helps a little.
Sounds like this is what I am after... Does this also work when all your navigations links are stored in tow includes files? How do you call a function for each navigation link? Never done function calls with PHP...Then different question in same context: what is the difference between print and echo? I used both as "echo $_SERVER['PHP_SELF'] and print $_SERVER['PHP_SELF']" to see how it works, but seems to do the same...Kurt
Link to comment
Share on other sites

Yeah that should work fine, you just need to make sure that the function is visible when you're calling it. The contents of includes should be processed after they're included so any function calls should be able to call any functions visible to the main document. Once you've written the function you'll want to call the function something like this:<?php linkFunction("/dir/page.php", "Home") ?>Thats it, the real work is in the function where you have to decide whether "/dir/page.php" is the page you're currently on then output the correct thing.The differences between print and echo are quite subtle and not worth worrying about most of the time. The main differences are that print returns a value whereas echo doesn't and echo can take multiple expressions to output (e.g. echo "str1", "str2":). Echo is marginally faster because it doesn't have to return a value, but the difference is insignificant in most uses.

Link to comment
Share on other sites

Yeah that should work fine, you just need to make sure that the function is visible when you're calling it. The contents of includes should be processed after they're included so any function calls should be able to call any functions visible to the main document. Once you've written the function you'll want to call the function something like this:<?php linkFunction("/dir/page.php", "Home") ?>Thats it, the real work is in the function where you have to decide whether "/dir/page.php" is the page you're currently on then output the correct thing.The differences between print and echo are quite subtle and not worth worrying about most of the time. The main differences are that print returns a value whereas echo doesn't and echo can take multiple expressions to output (e.g. echo "str1", "str2":). Echo is marginally faster because it doesn't have to return a value, but the difference is insignificant in most uses.
Thank you for your input. Will have a go and see how it works in detail...;-)Kurt
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...