Skip to content Skip to sidebar Skip to footer

Php File Layout/design

I would like to create a site in php that works the same way that https://www.bitcoins.lc/ does, in terms of it having the same layout on each page but the content would change as

Solution 1:

Here's the approach I generally take to this:

FILES:

  • layout.php
  • index.php
  • views
    • _index.php

layout.php:

<html><head><title><?phpecho$title; ?></title></head><body><?phpinclude($childView); ?></body></html>

_index.php:

<section>
    Some page content
</section>

index.php:

<?php$title = 'Home';
    $childView = 'views/_index.php';
    include('layout.php');
?>

Basically, the page itself tells the layout what view to inject into the content area. It's similar to how you would use ASP.NET ContentPlaceholder elements.

Solution 2:

You could include a header and a footer in each page:

<?phpinclude('header.php');
?>
Welcome to my page
<?phpinclude('footer.php');
?>

Put the header and navigation in header.php, and the footer in footer.php.

Solution 3:

Hope you are worried about MVC as you are reading complex documentations about that. I would suggest you to go through a documentation which helps you to easily understand and create an MVC Framework. It will not be good if you move forward with your project without understanding its basics. Please have a look at the following article and let me know if it helps. Feel free to contact if you need any support.

http://www.henriquebarroso.com/how-to-create-a-simple-mvc-framework-in-php/

Solution 4:

The simplest approach is the one described by Sjoerd. If your page only contains some few elements, there is noting wrong with a switch or if statement.

index.php:

<html><body><!-- Wrapper div --><divid="wrapper>


            <!-- Header div -->
            <div id="header"><?phpinclude('header.php'); // File containing header code?></div><!-- Content div --><divid="content"><!-- Left Colon div --><divid="leftCol"><?phpinclude('leftMenu.php'); // File containing the menu?></div><!-- Center colon --><divid="centerCol"><?php$page = $_GET['page']; // To get the pageif($page == null) {
                            $page = 'index'; // Set page to index, if not set
                        }
                        switch ($page) {

                            case'index':
                                include('frontPage.php');
                                break;

                            case'about':
                                include('about.php');
                                break;

                            case'contact':
                                include('contact.php');
                                break;
                        }

                    ?></div></div><!-- Footer div --><divid="footer"><?phpinclude('footer.php'); // File containing the footer?></div></div></body></html>

header.php:

<?phpecho"This is header";   
?>

leftMenu.php:

<?phpecho"<a href='index.php/?page=index'>Front Page</a>"; // set page to indexecho"<a href='index.php/?page=about'>About</a>";      // page = aboutecho"<a href='index.php/?page=contact'>Contact</a>";  // page = contact?>

and so on

Post a Comment for "Php File Layout/design"