Newbie Conditional Question
Moderator: General Moderators
Newbie Conditional Question
Hi guys, can I do something like this:
<?php
If(...){
?>
regular HTML here
<?php
}
else{
?>
regular HTML here
<?php
}
?>
It would be very difficult for me to echo the HTML code because there is so much of it. Thanks.
<?php
If(...){
?>
regular HTML here
<?php
}
else{
?>
regular HTML here
<?php
}
?>
It would be very difficult for me to echo the HTML code because there is so much of it. Thanks.
I have to respectfully disagree; I echo all my HTML code. If you use heredoc syntax for large pieces of code, it's easy to echo out, you don't need to escape anything. I make a function like printJobTable(); which references this large piece of code. This makes my php page look like pseudocode, very easy to follow:
printStartHeader();
printJavaScript();
printEndHeader();
printJobTable();
printCandidatePool();
printFooter();
This makes it very easy to drill down problems, and anyone who has to maintain my code in the future should find it very easy, I think.
printStartHeader();
printJavaScript();
printEndHeader();
printJobTable();
printCandidatePool();
printFooter();
This makes it very easy to drill down problems, and anyone who has to maintain my code in the future should find it very easy, I think.
This is getting a little OT, but here's my take. No function of mine ever generates output; they return strings that the main script will echo (or do something else to). This comes in handy if you want to echo htmlspecialchars($page) to see the source to a paticular part that causing problems on some browsers that won't show source for a post'ed form.
Here's a skeleton of how I tend to do it
HTMLDisplay for me tends to be a subclass of "UIBase" fo situations where I want an alternate format for the same data. HTMLDisplay also tends to have a myriad of helper functions, listToRadioButton, formatTable, and other tools for site templating.
Here's a skeleton of how I tend to do it
Code: Select all
$display = new HTMLDisplay($language);
$page = $display->beginPage($title);
$page .= $display->showNavBar($curPage);
if ($user->isLoggedIn())
$page .= $display->showSomething($user);
else
$page .= $display->showLoginForm();
$page .= $display->endpage();
echo $page;I like that, nielsene, but I try to avoid objects in my PHP because $this->function(); is half the speed of function();. Also, for debugging, I tend to just edit the function itself to do htmlspecialchars or print_r or whatever needs to be seen. I do like your method though, I'll try it when php 5 comes out.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
One last OT point...
llimlib and nielsen;
Your way(s) are what I'm trying to elevate my level of coding to...moving from a procedural way of thinking to a more modular and ultimately OO way.
With new programmers, of which I count myself one, it's real easy in PHP to go procedural as it's generally quicker to code.
I posted a suggestion in the Suggestins forum HERE
llimlib and nielsen;
Your way(s) are what I'm trying to elevate my level of coding to...moving from a procedural way of thinking to a more modular and ultimately OO way.
With new programmers, of which I count myself one, it's real easy in PHP to go procedural as it's generally quicker to code.
I posted a suggestion in the Suggestins forum HERE
I wasn't going to say it over there, but mac alluded to it: coding above the "howto" level is very much a matter of personal style and experience. That sort of tutorial wouldn't make sense, because you've just got to develop your own personal style. The only way to do that is to make a ton of mistakes.