Php 404页面重定向

时间:2013-04-04 12:22:32

标签: php html

我在设置重定向页面时遇到问题。它似乎没有加载。

目前我有这个 它为页面做了案例,但由于某种原因它没有去defualt? 提出页面不存在。

这个位不起作用它不会因某种原因切换到默认值?

   //get the page information
    $pageInfo = $model -> getPageInfo($_GET['page']);

    //select which page to include when the user clicks
    //on either register/home/my account/my bids/my sell/completed auctions/edit etc..etc..etc..
    switch($_GET['page']) {

        case 'Register':
            include 'views/register.php';
            $view = new HomeView($pageInfo, $model);
            break;

        case 'Home':
            include 'views/homeView.php';
            $view = new HomeView($pageInfo, $model);
            break;

        case 'My Account':
            include 'views/myaccount.php';
            $view = new myaccount($pageInfo, $model);
            break;

        case 'My Bids':
            include 'views/mybids.php';
            $view = new Mybids($pageInfo, $model);
            break;

        case 'My Sell':
            include 'views/mysell.php';
            $view = new mysell($pageInfo, $model);
            break;

        case 'Completed Auctions':
            include 'views/checkout.php';
            $view = new checkout($pageInfo, $model);
            break;

        case 'editProduct':
            include 'views/editProductView.php';
            $view = new EditProductView($pageInfo, $model);
            break;

        case 'addProduct':
            include 'views/addProductView.php';
            $view = new AddProductView($pageInfo, $model);
            break;

        case 'deleteProduct':
            include 'views/deleteProductView.php';
            $view = new DeleteProductView($pageInfo, $model);
        break;

        case 'deleteUser':
            include 'views/deleteUserView.php';
            $view = new DeleteUserView($pageInfo, $model);
        break;

        case 'search':
            include 'views/search.php';
            $view = new search($pageInfo, $model);
        break;   

        case 'product':
            include 'views/productView.php';
            $view = new ProductView($pageInfo, $model);
        break;

        default: 
            include 'views/404.php';
            $view = new error($pageInfo,$model);
        break;

2 个答案:

答案 0 :(得分:0)

第一:我认为break;指令不需要default:

第二,如果我是你,我会补充一下。

if(!$_GET['page'] && empty($_GET['page'])){
include 'views/404.php';
$view = new error($pageInfo,$model);

}

因此,如果未设置页面ID,则只能回显默认值,即

答案 1 :(得分:0)

if($_GET['page']){
    switch ($_GET['page']) {
    case 'product':
        include 'views/productView.php';
        $view = new ProductView($pageInfo, $model);
        break;
    default:
        include 'views/404.php';
        $view = new error($pageInfo,$model);
    }
}    

应该有效。 确保在if($_GET...检查

中添加一些额外的验证