>     <?php require("mylib.php"); ?>
>     <html>
>     <head>
>      <?php myheader("this is the title"); ?>
>      <meta name="keywords" content="apples, oranges">
>     ...
>     </head>
>     <?php mybody("this is the title"); ?>
>     <p>here is the body of the page</p>
>     <?php myfooter(); ?>
>     </html>
>
> My questions are:
> 1. every page on the site has:
>     require("mylib.php");
> at the top of the page to provide access to the functions contained
> therein. Is require() correct or should I use include()?

require is correct.  include should be used if the file is being included
conditionally.  Since this is not a conditional include, require is the
right approach.

> 2. should mylib.php be called mylib.inc instead? It works fine
> as mylib.php. If I use include() instead  of require() would the
> filename extension be different, i.e. mylib.inc?

The extension name is arbitrary.  I prefer to use .inc and then have an
Apache httpd.conf rule to block direct access to .inc files just to
prevent people from accessing my include files directly.  In your case
someone could load up blah.com/mylib.php directly and your code may not be
wirtten to be executed out of context like that.

> 3. I pass the same title to myheader() and to mybody() as shown
> above. In the first case, it is emitted as <title>...</title> and in the
> 2nd case is it emitted as <h1>...</h1>. Is there a way to set this
> up so I only need to have one instance of the title passed to
> a function?

In your myheader() function you could have:

  function myheader($str) {
    global $title = $str;
    ...
  }

then in mybody():

  function mybody() {
    global $title;

    echo "<h1>$title</h1>\n";
    ...
  }

> 4. I have some of the HTML <xxx> tags in the code (i.e.
> <title>, <body> and some in the actual xxx.php page, i.e.
> <html>, <head> (as above). I suppose myheader() could
> have emitted <html><head> and myfooter() could have
> emitted </html>. I'm trying to develop some sense of style
> for this, but I'm working in a vacuum. Are there any opinions
> or guidelines on how to write php code in terms of which tags
> are visible in the page and which tags are emitted by functions
> in other modules?

I tend to put anything that controls the overall style of my pages in a
separate include file so when I need to change the style I just have to
change it in one place.  And yes, for me that includes the <html> and
</html> tags.

> 5. I see there is a php.template newsgroup, but I couldn't really
> follow the conversations. Is that group for discussing ways to
> implement a design template in php so that all pages have the
> same appearance? I guess that's what I'm doing with my
> mylib.php module - the functions dump out the same nav bars
> to every page.

Sounds like you are on the right track.  And no, the php.template group is
not about that.

-Rasmus


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to