PHP Include Horror

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SndFX69
    New Member
    • Dec 2006
    • 4

    PHP Include Horror

    Hi All

    This is my first post, and I'm really happy to join you guys, and I hope I can contribute in the best way I can.

    Ok, enough with the nice talk... Here is my problem


    I've created a PHP template using :
    header.php
    footer.php
    fucntions.php
    >>Template folder with:
    header.htm
    footer.htm

    Here is my big Q?

    How can I use the Include() to keep any PHP script inside the template.

    Ok, let me make this easy to understand

    I have a script called \HelpDesk\index .php I wuold like to use my template on this script and on any other PHP script, it works fine for the first page only, but if I click on any link on the HelpDesk/index.php it opens the script with out the template.

    I would like to run the whole script inside my template, can that be done?

    Thank you in advance for your support.

    Regards,
    Sndfx69
  • subbukumararaja
    New Member
    • Dec 2006
    • 4

    #2
    As per my understanding, u r saying that the template that u have included in the first page, is not displayed in the second page. right?

    if u want your template to be in every php script that u r going to call, then u have to include that template in all the available php scripts.

    For eg,

    inlclude("heade r.php")

    include("Naviga tion_menu.php") ;

    include("funcat ional_part.php" )


    include("footer .php");

    In that, the functional part will vary for every page and the rest of the things will remain same. So u have to inlclude the the header,footer and menu in all the pages.

    Comment

    • SndFX69
      New Member
      • Dec 2006
      • 4

      #3
      Thanks subbukumararaja for your reply

      and man that's going to be hard work, don't we have another easy way to do this, imagin if I had 50+ php files.

      Comment

      • steven
        New Member
        • Sep 2006
        • 143

        #4
        There are easier ways, but perhaps maybe more complicated in their initial setup.

        There are many free template parsers available, or you can write your own, which is what I did.

        Basically, my websites can consist of one, or maybe more, but very few individual PHP files. The rest if left to the libraries I wrote. Basically, my index.php does all the work based on user input and passes an array of data to my template parser php file. I can then have a template directory full of files. The template parser uses the file I specify in the index.php (based on the page the user wants to see) and then it goes through the html file, replacing specific tags with corresponding data in the array. It can also traverse arrays to repeat data, such as traversing an array to populate a table.

        One of the popular free parsers is smarty. http://smarty.php.net/

        Comment

        • b1randon
          Recognized Expert New Member
          • Dec 2006
          • 171

          #5
          Originally posted by steven
          There are easier ways, but perhaps maybe more complicated in their initial setup.

          There are many free template parsers available, or you can write your own, which is what I did.

          Basically, my websites can consist of one, or maybe more, but very few individual PHP files. The rest if left to the libraries I wrote. Basically, my index.php does all the work based on user input and passes an array of data to my template parser php file. I can then have a template directory full of files. The template parser uses the file I specify in the index.php (based on the page the user wants to see) and then it goes through the html file, replacing specific tags with corresponding data in the array. It can also traverse arrays to repeat data, such as traversing an array to populate a table.

          One of the popular free parsers is smarty. http://smarty.php.net/
          Boooooo, there's a much easier way. Go object-oriented. Make an abstract class that includes all of the template file you want to be in all of your pages. Then, when you make a new page make it an object too that extends your base class. Then you have all of your templates in only 1 file and don't have to go out and get a parser or mess with any code that isn't yours.

          Comment

          • steven
            New Member
            • Sep 2006
            • 143

            #6
            My method is completely OOP.

            The parser is a class, the db access is a class, the website php is a class, which extends a shared code abstract class, along with the ajax calling php script.

            You can't get much more OOP than the method I took.

            What you're suggesting still involves mixing php and html together. It's an awful working methadology. It's nasty on so many levels. It's like having inline css and javascript in your html files.

            Comment

            • b1randon
              Recognized Expert New Member
              • Dec 2006
              • 171

              #7
              Originally posted by steven
              My method is completely OOP.

              The parser is a class, the db access is a class, the website php is a class, which extends a shared code abstract class, along with the ajax calling php script.

              You can't get much more OOP than the method I took.

              What you're suggesting still involves mixing php and html together. It's an awful working methadology. It's nasty on so many levels. It's like having inline css and javascript in your html files.
              Steven, you must be misunderstandin g me. I'm talking about putting only the include statements in an abstract class and then inheriting that. There is no css, html, or javascript being mixed with php when you do that.

              Anyway it sounds like you got offended that I suggested using an OOP concept as a solution. I wasn't trying to mess with you mojo man, just to suggest a solution. Since you're taking potshots at my suggestion I guess my help is unwanted. If you do decided that perhaps you like to understand more clearly what I'm suggesting just send me a PM, otherwise I'm done with this discussion.

              Comment

              • AricC
                Recognized Expert Top Contributor
                • Oct 2006
                • 1885

                #8
                Gentlemen, lets take a step back here. I think both of you have good solutions to the problem. Let sndfx69 pick the solution he thinks will work best. I personally like to make it simple and make 1 index.php page with nothing but includes then I don't have to worry about parsing anything, although most of my sites are not data driven.

                Sndfx69 I think the include problem you are having is with your path's if you have it working with index.php but not your other files check the path you are using to include the scripts.

                HTH,
                Aric

                Comment

                • AricC
                  Recognized Expert Top Contributor
                  • Oct 2006
                  • 1885

                  #9
                  Originally posted by steven
                  It's like having inline css and javascript in your html files.
                  Hey... I like inline CSS ;(

                  Comment

                  • ronverdonk
                    Recognized Expert Specialist
                    • Jul 2006
                    • 4259

                    #10
                    Originally posted by AricC
                    Hey... I like inline CSS ;(
                    So do I AricC! And the reason is that you can have a zillion CSS definitions in an external file, but that also makes it the more difficult to maintain if you only use it only few times. Using external CSS is fine as long as it concerns site-wide usage. When it is only used for say, some ad-hoc table, cell, span, or whatever definitions, inline CSS makes it a lot easier to see immediately what its purpose is.

                    Ronald :cool:

                    Comment

                    Working...