Serve multiple pages from 1 PHP file?

前端 未结 5 1308
失恋的感觉
失恋的感觉 2021-01-19 15:23

So basically i am struggling with the need of optimizing my code for some project of mine. Currently i have pages like add_company.php, view_company.php

5条回答
  •  情书的邮戳
    2021-01-19 15:56

    This is pretty simple stuff. It should look something like this:

    //index.php
    if (!isset($_GET['page']))
        {
        require('index_contents.php');
        }
    else if ($_GET['page'] == 'company')
        {
        if (!isset($_GET['action']))
            {
            require('company_contents.php');
            }
        else if ($_GET['action'] == 'edit')
            {
            require('edit_company.php');
            }
        else if ($_GET['action'] == 'add')
            {
            require('add_company.php');
            }
        else
            {
            require('company_contents.php');
            }
        }
    else
        {
        require('index_contents.php');
        }
    

提交回复
热议问题