[Phpwm] Site Structure

Joe Beard joe.beard at gmail.com
Fri Dec 9 18:07:50 GMT 2005


The switch statement also allows you to mask the file names you are
calling, making your URLs look prettier :)

but

$found=false;
if(isset($_GET['page'])) {
 $desired_page = $_GET['page'];
 $allowable = array("index", "aboutme", "foo", "bar", "something", "else");
 foreach($allowable as $ok) {
 if($ok == $desired_page) {
 include($ok);
 $found=true;
 continue;
 }
 }
}


could be writen:

if (in_array($_GET['page'], array("index", "aboutme", "foo", "bar",
"something", "else")){
include($_GET['page'].'php');
}else{
include($default);
}

I think that looks clearer, but then thats just personal coding styles.

joe



On 12/9/05, David Goodwin <david at codepoets.co.uk> wrote:
> Matt Harris wrote :
> > Thanks for your reply David.
> >
> >   With the method you described using the front controller. How would I  redirect users? As there would be output before the PHP which would  cause an error with the header() wouldn't it?
> >
> >   Thanks again for you advice.
> >
>
> The front controller would be the gateway to your website. To enforce
> this you could do something like :
>
> if(!defined(IN_MYAPP)) {
>         die("Get lost");
> }
> in the top of all files, aside from the index.php one.
>
> index.php could have :
> <?php
>  /* I think this is how define's work, I may be wrong */
> define(IN_MYAPP, "yes");
>
> include("header.php");
> $found=false;
> if(isset($_GET['page'])) {
>  $desired_page = $_GET['page'];
>  $allowable = array("index", "aboutme", "foo", "bar", "something", "else");
>  foreach($allowable as $ok) {
>   if($ok == $desired_page) {
>    include($ok);
>    $found=true;
>    continue;
>   }
>  }
> }
> if(!$found) {
>     // include default content.
> }
> include("footer.php");
> ?>
>
> The only problem with the above, is that as you rightly said, once
> the header is included, if it writes out to the page, then it's not
> possible to do any sort of session management or header stuff.
>
> One way aronnd this would be to do something like :
>
> index.php :
>
> <?php
>  /* I think this is how define's work, I may be wrong */
> define(IN_MYAPP, "yes");
>
> $found=false;
> if(isset($_GET['page'])) {
>  $desired_page = $_GET['page'];
>  $allowable = array("index", "aboutme", "foo", "bar", "something", "else");
>  foreach($allowable as $ok) {
>   if($ok == $desired_page) {
>    include($ok);
>    $found=true;
>    continue;
>   }
>  }
> }
> if(!$found) {
>     // include default content.
> }
> include("header.php");
> echo $content; /* <--- NEW BIT */
> include("footer.php");
> ?>
>
> and $randomPage looks something like :
> <?php
> if(!defined(IN_MYAPP)) {
>         die("Get lost");
> }
> $content = "A long string full of html for this page...\n";
> ?>
>
> Which would work...... but you might dislike it.
>
>
> I'm fairly sure there is a better approach, using something like Smarty
> templates, but I've not got enough experience of them to say anything,
> yet. (I'm probably safe in assuming that Smarty provides some sort of
> include mechansim). Hopefully someone else here can clarify (or suggest
> a better approach).
>
> David.
> --
> David Goodwin
>
> [ david at codepoets dot co dot uk ]
> [ http://www.codepoets.co.uk       ]
>
> _______________________________________________
> Phpwm mailing list
> Phpwm at mailman.lug.org.uk
> http://mailman.lug.org.uk/mailman/listinfo/phpwm
>



More information about the Phpwm mailing list