1

嗨,我正在处理页面切换代码,由于某种原因,默认页面似乎没有加载,有人可以帮忙吗?目前我可以输入一个随机 URL,但它只是显示找不到页面。

默认显示会触发 PHPMyAdmin 页面错误
,即views/404.php文件夹。
但它没有。我似乎可以理解为什么它没有。

<?php
//begin the webpage
//index page selector placed into an array for options for the user to select


//session started recording attributes
session_start();

error_reporting(0);

//including other view class and model class function to be used on this page
include 'views/viewClass.php';
include 'classes/modelClass.php';


class PageSelector {
    public function run() {
        //has the user decided which page to go to?
        //if not then we will direct him to the homepage
        if(!$_GET['page']) {
            $_GET['page'] = 'Home';
        }

        //extending a new model class
        $model = new Model;

        //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);




        }
        echo $view -> displayPage();

    }    

}

$pageSelect = new PageSelector();
$pageSelect -> run();
//calls the selector to run after user has selected.
4

2 回答 2

0

I am going to assume that you are properly routing the 404s to this file. What is happening is that because the 404 doesn't have a $_GET['page'] your code is setting itself to be home and loading the home page.

Assuming this is the index.php file I would add a conditional to check for this and change the default to a case 404. This is the new code in full.

<?php
//begin the webpage
//index page selector placed into an array for options for the user to select


//session started recording attributes
session_start();

error_reporting(0);

//including other view class and model class function to be used on this page
include 'views/viewClass.php';
include 'classes/modelClass.php';


class PageSelector {
    public function run() {
    //Check to make sure they are loading a legit page first
    if($_SERVER['PHP_SELF'] != 'index.php'){
        $_GET['page'] = '404';
    }
    //has the user decided which page to go to?
    //if not then we will direct him to the homepage
    if(!$_GET['page']) {
        $_GET['page'] = 'Home';
    }

    //extending a new model class
    $model = new Model;

    //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;

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



        }
        echo $view -> displayPage();

    }    

}

$pageSelect = new PageSelector();
$pageSelect -> run();
//calls the selector to run after user has selected.
于 2013-04-04T13:51:05.327 回答
0

尝试改变

if(!$_GET['page']) {

if(!isset($_GET['page']) || $_GET['page'] == '') {
于 2013-04-04T13:39:17.063 回答