Re: 'nested conditional' that can identify parent page?



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. :)

.



Relevant Pages

  • Re: How do we get there from here?
    ... > then sub the whole of that generated markup into the template? ... layed out on the fly, a simple IMG tag, or even an entire HTML document. ... PHP scripting provides 10 times the features of both of these ... idea as tokens can eliminate a huge amount of maintance, ...
    (comp.databases.pick)
  • Re: A better XSS trap (Feedback wanted)
    ... better to always be forced to choose the right filter depending on the ... It makes template code shorter, ... and easier to understand for non-programmers (doing the HTML design). ... I personally stick to PHP only, because the I gain of a template engine ...
    (comp.lang.php)
  • Re: Separation of logic, design and data
    ... That is the weakness of using includes for HTML pieces. ... <?php include 'headerstuff.php'; ?> ... and now I'm here at my Template ... I'm sure at some point in the future I'll see the weaknesses in my ...
    (comp.lang.php)
  • Re: Methods of marking a menu with the current page.
    ... Would it be normal to have HTML tags inside a PHP script when they ... In a PHP page only the bits between the are php code. ... An array of 6 items called "menu", ... So, on the first loop $key contains "/index.php", $location ...
    (alt.html)
  • Re: best way for PHP page
    ... WYSIWYG html editor and work with other colleagues who have no php ... I can then call the template from a function feeding the title and any ... interactivity and client/server interactivity. ...
    (php.general)