php include design question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Floortje

    #16
    Re: php include design question

    Mark wrote:
    Which frameworks? The only other site that I've seen doing this is
    deviantART. It seems to use AJAX to load the main content and sidebar
    separately, but gracefully downgrades if you disable JavaScript.
    >
    That means that you need a file containing just the bare content so
    that you can load it into the page when navigating through the
    sidebar, but it needs to load the entire page when you access it
    directly... unless you have two copies of every page, one with the
    header and footer and one without, but that sounds terrible.
    >
    If you could point me to some frameworks that do this, it would be
    much appreciated. I don't even know what to search for.
    ZEND CakePHP symfony Codeigniter PRADO for example but really anything
    will do. Any simple cms will also have this option ot atleast a plugin
    to make this happen.


    Comment

    • Mark

      #17
      Re: php include design question

      On Aug 14, 12:10 pm, Michael Fesser <neti...@gmx.de wrote:
      .oO(Mark)
      >
      >
      >
      On Aug 14, 10:30 am, Michael Fesser <neti...@gmx.de wrote:
      .oO(Mark)
      >
      so, i'm making a website. let's say i have header.php, footer.php and
      content.php.
      >
      now in index.php I simply want to include the 3 pages. easy enough to
      do.
      but let's say the user navigates to mysite.com/content.php. now the
      header and footer will appear to be missing.
      so now the question is, how can i include the header and footer in
      content.php only if the page isn't already nested?
      >
      Why do you want the content.php to be callable? Includes should be
      stored outside the document root, so that they can't be reached by a
      URL. Then you won't have this problem at all.
      >
      Micha
      >
      Well, how else are people going to bookmark a particular page, or link
      it to their friends? If I don't make it accessible somehow, the only
      way people will be able to get to it is by going through the index.
      >
      It's still not exactly clear what you want. If the content.php just
      contains the content of a single page, then it should not be directly
      callable, as said. But if it's an entire page instead, then there's no
      point in including it in the index.php ... what am I missing?
      Micha
      I want it to be directly callable so that people can link their
      friends to it. I just want to make sure its properly nested between
      the header and footer at all times; whether it's inserted via ajax, or
      whether its called directly.

      Let's say that in index.php I include header.php, content.php and
      footer.php. Then, a user clicks a link on the page. I want to swap out
      content.php with content2.php using ajax. Easy enough to do. *But* I
      also want the URL to display mysite.com/content2.php so that users can
      send that link to their friends. So in a sense, content2.php needs to
      contain both just the bare content, and the full site (header+footer
      +content).

      Anyway, I did manage to find a way to do this by passing a parameter
      through ajax which tells it if it should be "bare" or "full". Except I
      ran into some issues where it wouldn't always load the page... so I'm
      sticking with a non-ajax site for now...

      There really needs to be a better way to do this. Most sites use the
      same and header and footer across all pages, there's really no need to
      reload them every time a user clicks a link.

      Comment

      • sheldonlg

        #18
        Re: php include design question

        Mark wrote:
        I want it to be directly callable so that people can link their
        friends to it. I just want to make sure its properly nested between
        the header and footer at all times; whether it's inserted via ajax, or
        whether its called directly.
        >
        Let's say that in index.php I include header.php, content.php and
        footer.php. Then, a user clicks a link on the page. I want to swap out
        content.php with content2.php using ajax. Easy enough to do. *But* I
        also want the URL to display mysite.com/content2.php so that users can
        send that link to their friends. So in a sense, content2.php needs to
        contain both just the bare content, and the full site (header+footer
        +content).
        Why not simply have:
        header.php
        footer.php
        inside1.php
        inside2.php

        index.php = header.php + inside1.php + footer.php (via includes)
        content2.php = header.php + inside2.php + footer.php (via includes)

        Why do you even need AJAX for this?

        I like a design that has something like this for page foo.php:

        <?php
        include 'php_header.php '; // Has things like session_start() , etc.
        $title = 'This is page foo";
        include 'foo_process.ph p';
        $html_include = 'foo_html.php';
        include 'template.php';
        ?>

        and then I would have in template.php all the basic html stuff, with an
        include of header.inc.php and footer.inc.php and in the content area I have
        <?php include $html_include; ?>

        That gives the same presentation over all pages and separates the page
        processing and page content presentation into two files which are
        included. All files for a page are tied together by the name "foo" and
        the page is callable as mysite.com/foo.php. To handle the form submit,
        I could either have it done in foo_process.php , or have a separate file
        foo_submit.php. Either way works. The point is that with this kind of
        arrangement you have consistency, yet have independent callable pages.

        Comment

        • Michael Fesser

          #19
          Re: php include design question

          ..oO(Mark)
          >I want it to be directly callable so that people can link their
          >friends to it. I just want to make sure its properly nested between
          >the header and footer at all times; whether it's inserted via ajax, or
          >whether its called directly.
          >
          >Let's say that in index.php I include header.php, content.php and
          >footer.php. Then, a user clicks a link on the page. I want to swap out
          >content.php with content2.php using ajax.
          Bad idea for at least two reasons:

          1) It requires JavaScript, which is not always available.
          2) The browser's address bar won't reflect the change, hence it would be
          impossible to bookmark these pages.
          >Easy enough to do. *But* I
          >also want the URL to display mysite.com/content2.php so that users can
          >send that link to their friends. So in a sense, content2.php needs to
          >contain both just the bare content, and the full site (header+footer
          >+content).
          Drop the entire AJAX idea, you don't really need it. In fact AJAX may
          cause severe usability and accessibility problems if not used properly.
          Instead build simple, flat pages, which include the header and footer.
          It's easy, reliable and efficient.
          >There really needs to be a better way to do this. Most sites use the
          >same and header and footer across all pages, there's really no need to
          >reload them every time a user clicks a link.
          You're trying to over-optimize and will cause new problems with that
          approach. There's nothing wrong with reloading header and footer on
          every page. Images (if there are any) are cached and some KB of HTML
          don't really matter. One URL, one document. It's that easy.

          Micha

          Comment

          • AqD

            #20
            Re: php include design question

            For files with only functions and classes (no html output), you could
            just use require_once().
            For html output ones, I strongly suggest you to choose one uniform
            style: either use the index.php to include header/footer and
            content.php and all other contents (act as the central dispatcher), or
            each of the user-reachable php files includes header/footer manually
            by require() - which is simple but requires code duplication.

            On Aug 14, 7:41 am, Mark <mnbaya...@gmai l.comwrote:
            so, i'm making a website. let's say i have header.php, footer.php and
            content.php.
            >
            now in index.php I simply want to include the 3 pages. easy enough to
            do.
            but let's say the user navigates to mysite.com/content.php. now the
            header and footer will appear to be missing.
            so now the question is, how can i include the header and footer in
            content.php only if the page isn't already nested?
            >
            i suppose i can include a variable in header.php that basically says
            "i've been included", and then in content.php if this variable isn't
            set, i could include them... is this the best/most elegant approach?

            Comment

            • Mark

              #21
              Re: php include design question

              On Aug 21, 12:28 pm, Michael Fesser <neti...@gmx.de wrote:
              .oO(Mark)
              >
              I want it to be directly callable so that people can link their
              friends to it. I just want to make sure its properly nested between
              the header and footer at all times; whether it's inserted via ajax, or
              whether its called directly.
              >
              Let's say that in index.php I include header.php, content.php and
              footer.php. Then, a user clicks a link on the page. I want to swap out
              content.php with content2.php using ajax.
              >
              Bad idea for at least two reasons:
              >
              1) It requires JavaScript, which is not always available.
              2) The browser's address bar won't reflect the change, hence it would be
                 impossible to bookmark these pages.
              >
              Easy enough to do. *But* I
              also want the URL to display mysite.com/content2.php so that users can
              send that link to their friends. So in a sense, content2.php needs to
              contain both just the bare content, and the full site (header+footer
              +content).
              >
              Drop the entire AJAX idea, you don't really need it. In fact AJAX may
              cause severe usability and accessibility problems if not used properly.
              Instead build simple, flat pages, which include the header and footer.
              It's easy, reliable and efficient.
              >
              There really needs to be a better way to do this. Most sites use the
              same and header and footer across all pages, there's really no need to
              reload them every time a user clicks a link.
              >
              You're trying to over-optimize and will cause new problems with that
              approach. There's nothing wrong with reloading header and footer on
              every page. Images (if there are any) are cached and some KB of HTML
              don't really matter. One URL, one document. It's that easy.
              >
              Micha
              1. That's the second reason it should be directly callable. It
              downgrades nicely. It will work both with and without Javascript. With
              Javascript enabled, it doesn't need to reload the headers and footers,
              without JS, it does.
              2. Actually, it will. It'll just contain a hash # symbol in the URL,
              ie, mysite.com/#mypage. I can also inject the page into the history so
              that the back, forward and bookmark buttons work.

              In fact, I got the whole thing working exactly like I've said, but on
              occasion Ajax would refuse to load a page. And I can't exactly have
              that sort of instability...

              Anyway, I guess you're right about the over-optimizing. I've scratched
              the Ajax stuff altogether. I'll look at it again in the future if it
              becomes a problem. Gmail and other sites (like DeviantART) do
              something like what I was mentioning, so there must be a benefit to
              it, and it's definitely do-able.

              Thanks.
              Mark

              Comment

              • Mark

                #22
                Re: php include design question

                On Aug 22, 6:32 am, AqD <aquila.d...@gm ail.comwrote:
                For files with only functions and classes (no html output), you could
                just use require_once().
                For html output ones, I strongly suggest you to choose one uniform
                style: either use the index.php to include header/footer and
                content.php and all other contents (act as the central dispatcher), or
                each of the user-reachable php files includes header/footer manually
                by require() - which is simple but requires code duplication.
                >
                On Aug 14, 7:41 am, Mark <mnbaya...@gmai l.comwrote:
                >
                so, i'm making a website. let's say i have header.php, footer.php and
                content.php.
                >
                now in index.php I simply want to include the 3 pages. easy enough to
                do.
                but let's say the user navigates to mysite.com/content.php. now the
                header and footer will appear to be missing.
                so now the question is, how can i include the header and footer in
                content.php only if the page isn't already nested?
                >
                i suppose i can include a variable in header.php that basically says
                "i've been included", and then in content.php if this variable isn't
                set, i could include them... is this the best/most elegant approach?
                Unfortunately the circumstances force me to use a non-uniform style,
                otherwise I'd happily stick with one.

                Mark

                Comment

                • Mark

                  #23
                  Re: php include design question

                  On Aug 20, 4:32 am, sheldonlg <sheldonlgwrote :
                  Mark wrote:
                  I want it to be directly callable so that people can link their
                  friends to it. I just want to make sure its properly nested between
                  the header and footer at all times; whether it's inserted via ajax, or
                  whether its called directly.
                  >
                  Let's say that in index.php I include header.php, content.php and
                  footer.php. Then, a user clicks a link on the page. I want to swap out
                  content.php with content2.php using ajax. Easy enough to do. *But* I
                  also want the URL to display mysite.com/content2.php so that users can
                  send that link to their friends. So in a sense, content2.php needs to
                  contain both just the bare content, and the full site (header+footer
                  +content).
                  >
                  Why not simply have:
                  header.php
                  footer.php
                  inside1.php
                  inside2.php
                  >
                  index.php = header.php + inside1.php + footer.php  (via includes)
                  content2.php = header.php + inside2.php + footer.php (via includes)
                  >
                  Why do you even need AJAX for this?
                  >
                  I like a design that has something like this for page foo.php:
                  >
                  <?php
                  include 'php_header.php ';  // Has things like session_start() , etc.
                  $title = 'This is page foo";
                  include 'foo_process.ph p';
                  $html_include = 'foo_html.php';
                  include 'template.php';
                  ?>
                  >
                  and then I would have in template.php all the basic html stuff, with an
                  include of header.inc.php and footer.inc.php and in the content area I have
                  <?php include $html_include; ?>
                  >
                  That gives the same presentation over all pages and separates the page
                  processing and page content presentation into two files which are
                  included.  All files for a page are tied together by the name "foo" and
                  the page is callable as mysite.com/foo.php.  To handle the form submit,
                  I could either have it done in foo_process.php , or have a separate file
                  foo_submit.php.  Either way works.  The point is that with this kind of
                  arrangement you have consistency, yet have independent callable pages.
                  I don't *need* Ajax, it's simply an efficiency thing. And I detest the
                  idea of having parallel files like that, but thanks for the suggestion
                  anyway. When I'm not using Ajax, I normally use a similar approach. I
                  try to be consistent where possible.

                  Mark

                  Comment

                  • Curtis

                    #24
                    Re: php include design question

                    Mark wrote:
                    On Aug 21, 12:28 pm, Michael Fesser <neti...@gmx.de wrote:
                    >.oO(Mark)
                    >>
                    >>I want it to be directly callable so that people can link their
                    >>friends to it. I just want to make sure its properly nested between
                    >>the header and footer at all times; whether it's inserted via ajax, or
                    >>whether its called directly.
                    >>Let's say that in index.php I include header.php, content.php and
                    >>footer.php. Then, a user clicks a link on the page. I want to swap out
                    >>content.php with content2.php using ajax.
                    >Bad idea for at least two reasons:
                    >>
                    >1) It requires JavaScript, which is not always available.
                    >2) The browser's address bar won't reflect the change, hence it would be
                    > impossible to bookmark these pages.
                    >>
                    >>Easy enough to do. *But* I
                    >>also want the URL to display mysite.com/content2.php so that users can
                    >>send that link to their friends. So in a sense, content2.php needs to
                    >>contain both just the bare content, and the full site (header+footer
                    >>+content).
                    >Drop the entire AJAX idea, you don't really need it. In fact AJAX may
                    >cause severe usability and accessibility problems if not used properly.
                    >Instead build simple, flat pages, which include the header and footer.
                    >It's easy, reliable and efficient.
                    >>
                    >>There really needs to be a better way to do this. Most sites use the
                    >>same and header and footer across all pages, there's really no need to
                    >>reload them every time a user clicks a link.
                    >You're trying to over-optimize and will cause new problems with that
                    >approach. There's nothing wrong with reloading header and footer on
                    >every page. Images (if there are any) are cached and some KB of HTML
                    >don't really matter. One URL, one document. It's that easy.
                    <snip>
                    Anyway, I guess you're right about the over-optimizing. I've scratched
                    the Ajax stuff altogether. I'll look at it again in the future if it
                    becomes a problem. Gmail and other sites (like DeviantART) do
                    something like what I was mentioning, so there must be a benefit to
                    it, and it's definitely do-able.
                    Their reasoning isn't necessarily optimization, it's to enhance the
                    web UI for the users, and make interacting more intuitive. However, in
                    Gmail, the user always has the option of using the standard HTML
                    interface.

                    If you're turning to "Ajax" to optimize things, you're either
                    optimizing prematurely, or not looking at the right places for dealing
                    with bottlenecks.

                    --
                    Curtis

                    Comment

                    • Mark

                      #25
                      Re: php include design question

                      On Sep 4, 2:10 am, Curtis <dye...@gmail.c omwrote:
                      Mark wrote:
                      On Aug 21, 12:28 pm, Michael Fesser <neti...@gmx.de wrote:
                      .oO(Mark)
                      >
                      >I want it to be directly callable so that people can link their
                      >friends to it. I just want to make sure its properly nested between
                      >the header and footer at all times; whether it's inserted via ajax, or
                      >whether its called directly.
                      >Let's say that in index.php I include header.php, content.php and
                      >footer.php. Then, a user clicks a link on the page. I want to swap out
                      >content.php with content2.php using ajax.
                      Bad idea for at least two reasons:
                      >
                      1) It requires JavaScript, which is not always available.
                      2) The browser's address bar won't reflect the change, hence it would be
                         impossible to bookmark these pages.
                      >
                      >Easy enough to do. *But* I
                      >also want the URL to display mysite.com/content2.php so that users can
                      >send that link to their friends. So in a sense, content2.php needs to
                      >contain both just the bare content, and the full site (header+footer
                      >+content).
                      Drop the entire AJAX idea, you don't really need it. In fact AJAX may
                      cause severe usability and accessibility problems if not used properly..
                      Instead build simple, flat pages, which include the header and footer.
                      It's easy, reliable and efficient.
                      >
                      >There really needs to be a better way to do this. Most sites use the
                      >same and header and footer across all pages, there's really no need to
                      >reload them every time a user clicks a link.
                      You're trying to over-optimize and will cause new problems with that
                      approach. There's nothing wrong with reloading header and footer on
                      every page. Images (if there are any) are cached and some KB of HTML
                      don't really matter. One URL, one document. It's that easy.
                      >
                      <snip>
                      >
                       Anyway, I guess you're right about the over-optimizing. I've scratched
                      the Ajax stuff altogether. I'll look at it again in the future if it
                      becomes a problem. Gmail and other sites (like DeviantART) do
                      something like what I was mentioning, so there must be a benefit to
                      it, and it's definitely do-able.
                      >
                      Their reasoning isn't necessarily optimization, it's to enhance the
                      web UI for the users, and make interacting more intuitive. However, in
                      Gmail, the user always has the option of using the standard HTML
                      interface.
                      >
                      If you're turning to "Ajax" to optimize things, you're either
                      optimizing prematurely, or not looking at the right places for dealing
                      with bottlenecks.
                      >
                      --
                      Curtis
                      Actually, there was one other reason I wanted to use Ajax. I wanted
                      the menu and the main content to load separately from eachother. I'm
                      going to have a tree menu, that expands as you click on it. I don't
                      want to refresh the page the entire page every time a user clicks
                      something. Yes, I could use *just* javascript for that, but I suspect
                      there will be hundreds, or even thousands of entries one day, so I
                      don't necessarily want to load the whole thing at once. And when a
                      user clicks a category, the main page should show a more detailed
                      listing...but the idea is that the user doesn't have to wait for it to
                      load if he doesn't want to. Anyway, not a big deal just yet.

                      Mark

                      Comment

                      • Jerry Stuckle

                        #26
                        Re: php include design question

                        Mark wrote:
                        On Sep 4, 2:10 am, Curtis <dye...@gmail.c omwrote:
                        >Mark wrote:
                        >>On Aug 21, 12:28 pm, Michael Fesser <neti...@gmx.de wrote:
                        >>>.oO(Mark)
                        >>>>I want it to be directly callable so that people can link their
                        >>>>friends to it. I just want to make sure its properly nested between
                        >>>>the header and footer at all times; whether it's inserted via ajax, or
                        >>>>whether its called directly.
                        >>>>Let's say that in index.php I include header.php, content.php and
                        >>>>footer.ph p. Then, a user clicks a link on the page. I want to swap out
                        >>>>content.p hp with content2.php using ajax.
                        >>>Bad idea for at least two reasons:
                        >>>1) It requires JavaScript, which is not always available.
                        >>>2) The browser's address bar won't reflect the change, hence it would be
                        >>> impossible to bookmark these pages.
                        >>>>Easy enough to do. *But* I
                        >>>>also want the URL to display mysite.com/content2.php so that users can
                        >>>>send that link to their friends. So in a sense, content2.php needs to
                        >>>>contain both just the bare content, and the full site (header+footer
                        >>>>+content) .
                        >>>Drop the entire AJAX idea, you don't really need it. In fact AJAX may
                        >>>cause severe usability and accessibility problems if not used properly.
                        >>>Instead build simple, flat pages, which include the header and footer.
                        >>>It's easy, reliable and efficient.
                        >>>>There really needs to be a better way to do this. Most sites use the
                        >>>>same and header and footer across all pages, there's really no need to
                        >>>>reload them every time a user clicks a link.
                        >>>You're trying to over-optimize and will cause new problems with that
                        >>>approach. There's nothing wrong with reloading header and footer on
                        >>>every page. Images (if there are any) are cached and some KB of HTML
                        >>>don't really matter. One URL, one document. It's that easy.
                        ><snip>
                        >>
                        >> Anyway, I guess you're right about the over-optimizing. I've scratched
                        >>the Ajax stuff altogether. I'll look at it again in the future if it
                        >>becomes a problem. Gmail and other sites (like DeviantART) do
                        >>something like what I was mentioning, so there must be a benefit to
                        >>it, and it's definitely do-able.
                        >Their reasoning isn't necessarily optimization, it's to enhance the
                        >web UI for the users, and make interacting more intuitive. However, in
                        >Gmail, the user always has the option of using the standard HTML
                        >interface.
                        >>
                        >If you're turning to "Ajax" to optimize things, you're either
                        >optimizing prematurely, or not looking at the right places for dealing
                        >with bottlenecks.
                        >>
                        >--
                        >Curtis
                        >
                        Actually, there was one other reason I wanted to use Ajax. I wanted
                        the menu and the main content to load separately from eachother. I'm
                        going to have a tree menu, that expands as you click on it. I don't
                        want to refresh the page the entire page every time a user clicks
                        something. Yes, I could use *just* javascript for that, but I suspect
                        there will be hundreds, or even thousands of entries one day, so I
                        don't necessarily want to load the whole thing at once. And when a
                        user clicks a category, the main page should show a more detailed
                        listing...but the idea is that the user doesn't have to wait for it to
                        load if he doesn't want to. Anyway, not a big deal just yet.
                        >
                        Mark
                        >
                        As Curtis said - you're optimizing prematurely.

                        Only a very few sites in the world ever get "thousands" of entries.
                        Many don't even get "hundreds" of entries.

                        And even if you do - how long is an entry? 1K entries at 10 bytes
                        apiece is still only 10K - you probably have larger pictures than that.

                        If load time because a problem, then it's time to look at the problem.

                        --
                        =============== ===
                        Remove the "x" from my email address
                        Jerry Stuckle
                        JDS Computer Training Corp.
                        jstucklex@attgl obal.net
                        =============== ===

                        Comment

                        Working...