dongzhuo6137 2011-06-26 09:46
浏览 100
已采纳

PHP文件布局/设计

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?

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

Any help or advice would be appreciated.

Jason

  • 写回答

4条回答 默认 最新

  • dongwuge6201 2011-06-26 14:19
    关注

    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 -->
            <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:

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

    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
    ?>
    

    and so on

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图