<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 2.3 路由類 ~~~ 1. 調整目錄結構 2. 路由類的作用 ~~~ ### 1. 調整目錄結構 把 `route.php` 這些類放在 `/core/lib` 中。 文件:`D:\wamp\www\web.com\core\route.php` 放在 `D:\wamp\www\web.com\core\lib\route.php` 因此:我們的**命名空間也將發生變化**,一下兩處修改了命名空間。 *D:\wamp\www\web.com\core\lib\route.php* ~~~ <?php namespace core\lib; class route { public function __construct() { echo "路由初始化成功"; } } ~~~ *D:\wamp\www\web.com\index.php* ~~~ // 實現自動加載 spl_autoload_register('\core\thinkphp::load'); ~~~ ### 2. 路由類的作用 以訪問地址`xxx.com/index.php/index/index` 為例。 1. 隱藏index.php,變為:`xxx.com/index/index` 2. 返回對應的控制器、方法,默認為`index` 3. 獲取URL參數的部分,帶參數的地址:`xxx.com/index/index/id/3` #### 2.1 去除index.php 這里以Apache服務器為例。 在根目錄下添加文件:`D:\wamp\www\web.com\.htaccess` ~~~ <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] </IfModule> ~~~ #### 2.2 使用超全局變量 `$_SERVER['REQUEST_URI']` 查看 `$_SERVER['REQUEST_URI']` 的值。 ![](https://box.kancloud.cn/bb1e8bcd25e14b2d271d8442c9ed8360_1366x728.png) *D:\wamp\www\web.com\core\lib\route.php* ~~~ <?php namespace core\lib; class route { public $ctrl; public $action; public function __construct() { /** * xxx.com/index.php/index/index * 1. 隱藏index.php * 2. 返回對應的控制器、方法 * 3. 獲取URL參數的部分 */ if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '/' ) { $path = $_SERVER['REQUEST_URI']; $pathArr = explode('/', trim($path, '/')); if (isset($pathArr[0])) { $this->ctrl = $pathArr[0]; } unset($pathArr[0]); if (isset($pathArr[1])) { $this->action = $pathArr[1]; unset($pathArr[1]); } else{ $this->action = 'index'; } // 把剩余的參數信息,寫入$_GET $count = count($pathArr) + 2; $i = 2; while ($i < $count) { if (isset($pathArr[$i + 1])) { $_GET[$pathArr[$i]] = $pathArr[$i + 1]; } $i += 2; } } else{ $this->ctrl = 'index'; $this->action = 'index'; } } } ~~~ #### 2.3 查看效果 在 *D:\wamp\www\web.com\core\thinkphp.php* ~~~ static public function run() { $route = new \core\lib\route(); // 打印路由對象 p($route); } ~~~ ![](https://box.kancloud.cn/709b4f611da6b5c1ead4d07f076157ac_738x314.png) 打印存儲的參數信息如下: ![](https://box.kancloud.cn/9e4b1c464bb54b219c549fe16db42e86_788x409.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看