Serve multiple pages from 1 PHP file?

前端 未结 5 1294
失恋的感觉
失恋的感觉 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:59

    I always prefer using a switch statement for the $_GET variable. Its my personal preference to put all the logic pertaining to one entity (in this case company) in a single PHP file because I generally deal with tons of entities. If you want a MVC model, this might not be what you are looking for. Just my 2 cents.

    // Common page header
    // Other stuff common in the pages
    
    $page_to_load = $_GET[view];
    
    switch($page_to_load) {
    
    case 'view':
    //Logic to view or HTML for view
    break;
    
    case 'add':
    //Logic to add or HTML for add
    break;
    
    }
    // Common footer etc..
    

提交回复
热议问题