在PHP

时间:2019-07-03 01:41:30

标签: php

我在php应用程序中使用名称空间,但是当我加载页面时会显示错误

  

致命错误:未捕获错误:在> C:\ xampp \ htdocs \ app \ index.php:10中找不到类'Route \ Router'堆栈跟踪:#0 {main}在> C:\ xampp \ htdocs中引发\ app \ index.php,第10行

        <?php

        require_once 'routes/Router.php';

        use Route\Router;

        $request = $_SERVER['REQUEST_URI'];
        $router = new Router($request);
        $router->get('/', 'view/index');
        $router->get('post', 'view/auth/login');

...

        <?php

        namespace Route;

        class Router
        {
            private $request;

            function __construct($request)
            {
                $this->request = $request;
            }

            public function get($route, $file)
            {
                $uri = trim($this->request, "/");
                $uri = explode("/", $uri);
                if ($uri[0] == trim($route, "/")) {
                    array_shift($uri);
                    $args = $uri;
                    require $file . '.php';
                }
            }
        }

0 个答案:

没有答案