Can I put entire pages inside php functions ?

Discussion in 'PHP' started by JohnnyCashpoint, Apr 24, 2009.

  1. #1
    Howdy.

    This is one concept of php that I'm fairly new to - and its hard to describe in google so I can't find results.

    Is it possible to have a single page which can show many different screens which exist in functions so the screen doesn't really refresh in the typical sense ?

    i.e.

    this-webpage.php

    (function with page a)

    (function with page b)

    (function with page c)


    I'm not sure if there would be problems with headers being sent or anything of that nature.

    Is this possible and if so, could anyone provide a little example please ?

    Many thanks.
     
    JohnnyCashpoint, Apr 24, 2009 IP
  2. JDevereux

    JDevereux Peon

    Messages:
    50
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You might want to look into AJAX. You could also do this with javascript using hidden divs. Also JQUERY which has some cool tabbing stuff.
     
    JDevereux, Apr 24, 2009 IP
  3. JohnnyCashpoint

    JohnnyCashpoint Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks. I'll have a gander at those options.

    I am thinking of modifying some separate pages that are already written in php but do a lot of redirecting (which isn't as clean as I'd like it to be).. I was hoping to kind of amalgamate them into functions within one page.

    If I were to attempt it in php, is it possible ?
     
    JohnnyCashpoint, Apr 24, 2009 IP
  4. JDevereux

    JDevereux Peon

    Messages:
    50
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I would think you'd use a javascript handler to call your php scripts via AJAX to display on the current page, but it really depends on what your scripts are doing.
     
    JDevereux, Apr 24, 2009 IP
  5. nayes84

    nayes84 Member

    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #5
    nayes84, Apr 25, 2009 IP
  6. wayfarer07

    wayfarer07 Peon

    Messages:
    34
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You can break from PHP and begin to output plain HTML inside of PHP functions. Then, you can break back into PHP inside of the plain HTML again, as many times as you like. As long as all of the output is inside the function brackets {} there is no problem.

    Example:
    
    <?php
    function page($data) {
    //do something with data, like retrieve information from database;
    ?>
    <html>
    <head>
    <title><?=$title?></titl>
    <meta name="description" content="<?=$meta_d?>" />
    </head>
    <body>
    <div id="wrapper">
    <div id="main">
    <?php
    // do something related to the main content
    ?>
    </div>
    <div id="sidebar">
    <?php
    // do something related to the sidebar
    ?>
    </div>
    </div>
    </body>
    <?php } //end of function
    ?>
    
    PHP:
    I find this a bit silly, but it is certainly possible.
     
    wayfarer07, Apr 25, 2009 IP