Understanding PHP actions
3 hours ago, Sergio45 said:So does the case statements have an order that there executed or are they executed the moment that there is a match of the case. I get that
case "firstPage": include_once("Views/firstPage.php"); break;Makes it show the firstPage.php when the action which is the name of the variable and firstPage which is what is assigned to that variable (action).
In the order of precedence. The block of the first matching case is run and no other case of the switch should be evaluated afterward if there's a break in the block.
QuoteShort version:I don't see the action firstPage being declared anywhere other than here:
$_REQUEST['action'] = (isset($_REQUEST['action']) ?$_REQUEST['action'] : "firstPage");Which is in the Index.php: I know that Index is the first thing that is loaded.
So does the above code start off assigned with the string value of "firstPage" the moment it is loaded....Right?
As long as $_REQUEST['action'] has not been set — which is, in your project's case (no pun intended), always — it will have "firstPage" assigned to it. The reason the "firstPage" case didn't run before was simply because of the lowercase 'p'
QuoteSo that is why we don't have to declare the action "firstPage" anywhere in the firstPage.php file because it is declared right of the bat and matches the case statement and loads the firstPage.php...Right?
Correct. Have you learned about compile vs runtime yet? At runtime, the code in firstPage.php is effectively considered as code within whatever file it was included by. I think what the assignment is trying to show with the header and footer is that instead of having to have the code from the header/footer files in each file that require it, you can simply include it instead. This makes for editing of code that is used by multiple files quicker and much more efficient.
If you ever have any questions about coding related topics, you're very welcome to message me and I'll link you my discord or Steam etc. I'm by no means the best web developer out there but I'm always happy to help with this sort of stuff
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now