Re: 'nested conditional' that can identify parent page?
- From: Alan Jones <alan@xxxxxxxxxxxxxx>
- Date: Mon, 14 May 2007 02:09:34 GMT
On 13 May 2007 18:42:28 -0700, shimmyshack <matt.farey@xxxxxxxxx>
wrote:
if you will need signature included for a set of files you know in
advance you could do this
(this example works for all index.php filenames because it uses
basename, if you need/want to specify filenames by their paths then
remove the basename part, and specify the files in the array including
their paths
$arrFileNamesWhereSignatureShouldAppear = array(
'index.php',
'contact.php'
);
if( in_array(basename($_SERVER['PHP_SELF']),
$arrFileNamesWhereSignatureShouldAppear) )
{
include('signature.php');
}
remember that this is NOT the simple way. All this might appear
simple, but the rub comes later when you relise you have to rewrite
everything to do something that would have been simple if you had
committed to the learning curve earlier.
You are encouraged to look at best practise examples and follow along,
before thinking you can rewrite the book with "5 minute home brew
architecture" trust me I learned this way too!
for instance here's a better way to include stuff. (still old style
non Object Oriented)
mainpage.php
<?php
#find page you are on from request uri
include('functions.php');
$arrayPageParts = get_page_info( $_SERVER['REQUEST_URI'] );
?>
<?php
#css just for this page
echo $arrayPageParts['css'];
'js just for this page
echo $arrayPageParts['js'];
?>
styles/js for everypage go here
<html><head>
<title><?php echo $arrayPageParts['title']; ?></title>
<?php echo output_meta_tag( $arrayPageParts['description']; ?>
<meta tags: language, description, keywords, etc...
<!--some comment-->
</head><body>
<?php
#this ['body'] could instead be
['menu']
more html...
['content']
etc.. so that more html is in the template, and content elsewhere
try to make as little php and html mix as possible, have a template
which is all the html you need, and fill with pure content
echo $arrayPageParts['body']; ?>
<?php echo $arrayPageParts['signature'];
#which of course is not there if the $page leads to this being null
?></body></html>
I mean this is by no means the right way of coding, but it is a very
simple "template"
the idea of includes can be useful but not as usefule as functions
which get the data and return it into an array
Once again, this might be arguably better, its no OO hMVC pattern but
hey it's better than writing condition includes in the main page, keep
on abstracting away your code into functions and return a array of
paragraphs, menu content etc.. free of html, and use while loops and
so on..
this way if you redesign the site, you just redesign the template, and
the content can come from a db or flat files or another website, you
dont care, and that makes it easy to add pages...
anyway matt out.
Thanks, I'll digest all that over time, as I continue learning. :)
.
- References:
- 'nested conditional' that can identify parent page?
- From: Alan Jones
- Re: 'nested conditional' that can identify parent page?
- From: shimmyshack
- Re: 'nested conditional' that can identify parent page?
- From: Alan Jones
- Re: 'nested conditional' that can identify parent page?
- From: shimmyshack
- Re: 'nested conditional' that can identify parent page?
- From: Alan Jones
- Re: 'nested conditional' that can identify parent page?
- From: shimmyshack
- Re: 'nested conditional' that can identify parent page?
- From: Alan Jones
- Re: 'nested conditional' that can identify parent page?
- From: shimmyshack
- 'nested conditional' that can identify parent page?
- Prev by Date: Re: 'nested conditional' that can identify parent page?
- Next by Date: Re: enable domxml in php4
- Previous by thread: Re: 'nested conditional' that can identify parent page?
- Next by thread: PHP and IPv6: what about?
- Index(es):
Relevant Pages
|