Johan Broddfelt
/* Comments on code */

Adding content

So now all we want to do is add some content. So we start by creating a structure in which we will organise our content. Create a folder called views, and inside that a folder called start. In the start folder we create the file main.php.


    Her is our start page

The dives are again used to create spacing without distorting the content element.
In order to get this into our page we can easily write the following in our printContent function in index.php

function printContent() {

And then we and this to our main.css

#content>div {
  padding: 20px;

This might be okey if we only should hav one page on our site. But we want to add a few more pages. Therefore we need to device a method to select what page to show. I would like my url to look like[module]&view=[view]&id=[id].

So lets try this by entering the following code into our printContent function
Read more about the filter_values filter here

function printContent() {
    echo 'Module: ' . filter_input(INPUT_GET, 'module', FILTER_SANITIZE_URL) . '<br>';
    echo 'View: ' . filter_input(INPUT_GET, 'view', FILTER_SANITIZE_URL) . '<br>';
    echo 'Id: ' . filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT) . '<br>';

Now you can see the data when you run this url: and with that data we can tell the php-code to show the page selected in the url like this.

function printContent() {
    $module = filter_input(INPUT_GET, 'module', FILTER_SANITIZE_URL);
    $view = filter_input(INPUT_GET, 'view', FILTER_SANITIZE_URL);
    $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
    // Get the page we want to display. If no module is provided we will get the start page
    if ($module == '') {
    } else {
        include('views/' . $module . '/' . $view . '.php');

We will save the id for later when we want to select data from the database to display. But with this knowledge I can go on and create my link page, about page and my start page. If no module is provided we will get the start page

Now let's add the following links in the menu of our main_template.php and as pages in our view folder

  <a href="index.php?module=page&view=links">Links</a>
  <a href="index.php?module=page&view=about">About</a>


    Here are some of the greatest resources on the Internet when it comes to web development. 
    If I have missed any, please feel free to mail me some more great ones.<br>


    Here goes some text about me...

Now we can click the links and vi the corresponding pages.

- Framework, PHP

Follow using RSS

<< Style your page How to use classes >>


Mail (Not public)
Send mail uppdates on new comments
0 comment