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 に答える