Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy. This forum is not for asking programming related questions.
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Hi Guys & Girls !
I am developing a little project for my own and I am using the same page to output every link within my site. So, when the user hits any link available, I have a $_GET and parse the correct path with, as Ex.: "if ($_GET["x"]){ include ("./path/toincluldepage.php");}elseif... "
I am not sure with but I am perceiving a strange behavior in the status bar of my FIREFOX, when I execute any of these links. I mean: it geting a little much longer to output the requested content. I must inform that, every page has DB access. So I ask you: is there a better way to reduce this or that strange behavior does not have any relation?
That s the condition used to parse any link in the index.php:
poeta_eletrico wrote:I am developing a little project for my own and I am using the same page to output every link within my site. So, when the user hits any link available, I have a $_GET and parse the correct path with, as Ex.: "if ($_GET["x"]){ include ("./path/toincluldepage.php");}elseif... "
That looks like a Front Controller.
Martin Fowler in PoEAA wrote:A Front Controller handles all calls for a Web site, and is usually structured in two parts: a Web handler and a command hierarchy. The Web handler is the object that actually receives post or get requests from the Web server. It pulls just enough information from the URL and the request to decide what kind of action to initiate and then delegates to a command to carry out the action (see Figure 14.2).
poeta_eletrico wrote:I am not sure with but I am perceiving a strange behavior in the status bar of my FIREFOX, when I execute any of these links. I mean: it geting a little much longer to output the requested content. I must inform that, every page has DB access. So I ask you: is there a better way to reduce this or that strange behavior does not have any relation?
If it seems slow to you maybe you should use an opcode cache to speed things up? Just kidding ... though of course that is an option. Getting rid of those if/else statements would help as suggested by Onion2k. Another option is eliminating the Front Controller and use Page Controllers instead.
PoEAA by Martin Fowler wrote:Page Controller:
An object that handles a request for a specific page or action on a Web site.
Most people's basic Web experience is with static HTML pages. When you request static HTML you pass to the Web server the name and path for a HTML document stored on it. The key notion is that each page on the Web site is a separate document on the server. With dynamic pages things can get much more interesting since there's a much more complex relationship between path names and the file that responds. However, the approach of one path leading to one file that handles the request is a simple model to understand.
As a result, Page Controller has one input controller for each logical page of the Web site. That controller may be the page itself, as it often is in server page environments, or it may be a separate object that corresponds to that page.
You would have to reorganize your program into pages however eliminating the if/then statements looks like a lot of work too.
$page = $_REQUEST['page'];
// check that $page is in an allowed list of pages
if (pageallowed($page)) {
include("inc/inc_{$page}.php");
} else {
// default content
}
I don't know if this is any faster. It'll depend on how the pageallowed() function is coded.
I've would do it defining an array that lists all the allowed pages then calling in_array().
onion2k wrote:You should definitely replace it with a switch..case statement rather than a bunch of if..else blocks.
Hi !
Sorry for the delay responding your post. Well, I imagine now that SWITCH would be faster than IF statement but I will consider what SHEILA respond as well. I will reorder things here and let u know !!
$page = $_REQUEST['page'];
// check that $page is in an allowed list of pages
if (pageallowed($page)) {
include("inc/inc_{$page}.php");
} else {
// default content
}
I don't know if this is any faster. It'll depend on how the pageallowed() function is coded.
I've would do it defining an array that lists all the allowed pages then calling in_array().
I take for reference your piece of code and mixed up with the one parsed by Jenk.
Thank you very much for your attention and this really help me a lot !
It really is something pretty simple, but, only when you have an wide view u can see the point to view