PHP文件布局/设计

问题描述:

我想在php中创建一个网站,该网站的工作方式与 https://www.bitcoins.lc/确实如此,因为它在每个页面上都具有相同的布局,但是内容会随着您更改链接/页面而改变,我该如何在php中使用layout.php和index.php以及header.php ect进行设置?

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 you change links/pages, how do I set this up in php with layout.php and index.php and header.php ect?

有人告诉我要阅读有关MVC框架的信息,但我并不是很了解.

I was told to read about MVC frameworks but I don't really understand it all.

任何帮助或建议,将不胜感激.

Any help or advice would be appreciated.

Jason

最简单的方法是Sjoerd描述的方法. 如果您的页面仅包含一些元素,则说明switch或if语句没有错.

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:

index.php:

<html>
    <body>

        <!-- Wrapper div -->
        <div id="wrapper>


            <!-- Header div -->
            <div id="header">
                <?php
                    include('header.php'); // File containing header code
                ?>
            </div>

            <!-- Content div -->
            <div id="content">


                <!-- Left Colon div -->
                <div id="leftCol">
                    <?php
                        include('leftMenu.php'); // File containing the menu
                    ?>
                </div>


                <!-- Center colon -->
                <div id="centerCol">
                    <?php
                        $page = $_GET['page']; // To get the page

                        if($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 -->
            <div id="footer">
                <?php
                    include('footer.php'); // File containing the footer
                ?>
            </div>
        </div>
    </body> 
</html>

header.php:

header.php:

<?php
    echo "This is header";   
?>

leftMenu.php:

leftMenu.php:

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

以此类推