PHP-макет / дизайн PHP

Я хотел бы создать сайт в php, который работает так же, как https://www.bitcoins.lc/ , с точки зрения того, что он имеет одинаковый макет на каждой странице, но содержимое будет меняться при изменении ссылок / страниц, как установить это в php с помощью layout.php и index.php и header.php ect?

Мне сказали читать о MVC-фреймворках, но я не совсем понимаю все это.

Любая помощь или совет будут оценены.

Джейсон

Самый простой подход – это тот, который описывается Сьёрддом. Если ваша страница содержит только несколько элементов, то с помощью оператора switch или if вы заметите ошибку.

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

и так далее

Вот такой подход, который я обычно делаю для этого:

ФАЙЛЫ:

  • layout.php
  • index.php
  • Просмотры
    • _index.php

layout.php:

 <html> <head> <title><?php echo $title; ?></title> </head> <body> <?php include($childView); ?> </body> </html> 

_index.php:

 <section> Some page content </section> 

index.php:

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

В основном, сама страница сообщает макет, какой вид следует вводить в область содержимого. Это похоже на то, как вы будете использовать элементы ASP.NET ContentPlaceholder.

Надеюсь, вас беспокоит MVC, когда вы читаете сложные документы об этом. Я бы предложил вам просмотреть документацию, которая поможет вам легко понять и создать MVC Framework. Это не будет хорошо, если вы продвигаетесь вперед с вашим проектом, не понимая его основ. Пожалуйста, ознакомьтесь со следующей статьей и дайте мне знать, если это поможет. Не стесняйтесь обращаться, если вам нужна поддержка.

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

Вы можете включить заголовок и нижний колонтитул на каждой странице:

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

Поместите заголовок и навигацию в header.php, а нижний колонтитул – в footer.php.