在PHP和include语句中使用URL变量


Using URL variables in and include statement PHP

我试图使用一个URL变量来触发哪个页面包含在PHP中的"Include"。这在Coldfusion中很简单,没有一堆if语句怎么能做到呢?

<a href="index.php?pageid=products" >products</a>
include('/inc'.$_GET['pageid']).'.php');

这可能是这个问题最短的代码:

创建一个名为:inc.404.php的文件来处理错误
<?php
    $page = (array_key_exists('page', $_GET) ? $_GET['page'] : '404');//we're sure that inc.404.php is there
    $filename = 'inc.' . $page . '.php';
    if(is_file($filename) === false){
       $filename = 'inc.404.php';
    }
    include $filename;
?>

但是使用PHP框架像symfony让世界变得更美好