0

我有一堂课...

class bootstrap {

    public static function redirect($ctrl = false, $act = false, $a = false)
    {
        echo 'Entered redirect ...';

        $url = array('home');
        if (!empty($_GET['url'])) {
            $url = rtrim($_GET['url'], '/');
            $url = explode('/', $url);

            print_r($url);
        }

        $controllerName = 'home';
        if (!$ctrl) {
            if (isset($url[0])) {
                $controllerName = $url[0];
            }
        }
        else {
            $controllerName = $ctrl;
        }

        echo '<br/>Controller: $controllerName';

        $file = './controllers/' . $controllerName . '.php';
        if (file_exists($file)) {
            require_once $file;
        }
        else {
            return false;
        }
        $controller = new $controllerName;

        $action = 'Index';
        if (!$act) {
            if (isset($url[1])) {
                $action = $url[1];
            }
        }
        else {
            $action = $act;
        }

        echo '<br/>Action: $action';

        $arg = false;
        if (!$a) {
            if (isset($url[2])) {
                $arg = $url[2];
            }
        }
        else {
            $arg = $a;
        }

        if (!$arg) {
            $controller->{$action}();
        }
        else {
            $controller->{$action}($arg);
        }
    }

}

index.php我试图调用这样的redirect函数......

include './core/init.php';

echo 'Calling redirect ...';
bootstrap::redirect();

现在,我echo 'Calling redirect ...';在页面上得到了 ,但我从来没有得到 ,echo 'Entered redirect ...';所以看起来它永远不会进入function.

希望有人可以帮助我...根据我在手册中阅读的内容,我认为我的课程设置正确。

4

1 回答 1

1

您的类引导程序必须在 init.php 中定义

伟大的:)

于 2012-12-15T14:53:46.550 回答