php - Having includes with variables in two places at once -


I have a small place here. I am creating custom CMS for one of my websites.

The code below is for the main index page:

   & Lt; Hour / & gt; & Lt; Br / & gt; & Lt; Div id = "content" & gt; & Lt ;? Php resonance $ content ['content']; ? & Gt; & Lt; / Div & gt; By & lt;? } Other {include ('/ include error / 404.php');}} (include '/ footer.php'); ? & Gt;  

The file contains the code to resize the variable in / header.php, such as page title and meta content.

The problem is that when is included ("include / header.php"); That is, where the situations are outside, it will not echo the varables, obviously, however, I can not include in the if condition otherwise, the home page, for which no URL variable is required, these conditions Will show up without

What do I do?

You can not actually write code in this way. It's OK to start, but you will soon find out that it is difficult to maintain. In general it is to split it in few steps.

  • First check on which page you are on
  • If you know that you are on the homepage, something like include / template / homepage.php < / Code>
  • otherwise try to load the page from the database
    • If this works, include the include / template / page .php
    • otherwise included / template / 404.php

Each of these contains the files / templates will output entire page, i.e. Include all the headers, include some and footer You can use, for example templates instead of PHP files, which approach will be clear.

Once you have this code, you can divide the code even further. Instead of loading the page directly from index.php, include another file that defines a function like load_page ($ name) and returns page details.

Then there is some more change and you realize that you are using the approach :) Databases are loading functions from your database, your model , smari templates view and those PHP files that put them together Controllers .


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -