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

                # (6)URL優化 #### 1. 隱藏index.php 即隱藏入口文件,官方鏈接,打開翻到最下面就能看到了:[http://www.hmoore.net/manual/thinkphp5/118012,](http://www.hmoore.net/manual/thinkphp5/118012%EF%BC%8C) 最新版本的框架寫的小項目都是不需要index.php就能訪問下去的,例如http://127.0.0.1/tp5/public/index/login/login 也能訪問到登錄界面,而我們主要做的就是怎么配置,讓url看起來更簡潔,最好是http//:域名/方法名,這種訪問方式。 #### 2. apache配置 這里我做的是加一個端口來做,本地的80 端口我在用 - 首先找到httpd-vhosts.conf,我這里的絕對路勁D:/wamp64/bin/apache/apache2.4.18/conf/extra/httpd-vhosts.conf - 然后在這個文件里面加上下面的代碼 ``` <VirtualHost *:8081> ServerName localhost DocumentRoot D:/wamp64/www/tp5/public <Directory "D:/wamp64/www/tp5/public/"> Options +Indexes +FollowSymLinks +MultiViews AllowOverride All Require local </Directory> </VirtualHost> ``` - 然后再在D:/wamp64/bin/apache/apache2.4.18/conf/original/httpd.conf文件下面加一個端口,Ctrl+f查找Listen,大概在下面代碼的位置,我加了一個Listen 8081,然后重啟apache, ``` # Change this to Listen on specific IP addresses as shown below to # prevent Apache from glomming onto all bound IP addresses. # #Listen 12.34.56.78:80 Listen 0.0.0.0:80 Listen [::0]:80 Listen 8081 Listen 8080 ``` - 接下來你再訪問http://127.0.0.1:8081/index/login/login, 也能進入到你的登錄界面,但是我這個里面,樣式文件竟然丟了,這是因為之前在配置文件里面寫的是:` ``` <?php return [ "web_root" => "/tp5/public/static/", "web" => "/tp5/public/index.php/", 'session' => [ 'auto_start' => true, 'name' => 'login@', 'expire' => 1800, /*時間長度*/ ], ]; ``` 現在需要把 "web\_root" => "/tp5/public/static/",改為 "web\_root" => "/static/",這樣樣式又回來了,到這里很多小伙伴肯定會想,與其在配置里面這樣寫,還不如不寫,直接將模板文件的 ``` <link rel="stylesheet" type="text/css" href="{$Think.config.web_root}css/main.css"> ``` 改為 ``` <link rel="stylesheet" type="text/css" href="/static/css/main.css"> ``` ,這里,我也是這樣改的,看起來會更舒服一點。 - 到這里,其實127.0.0.1:8081就是ServerName,也就是以后你的網址,后面的/index/login/login感覺還是太長了,這里還可以精簡,很多小伙伴到這里都會想到官方的綁定模塊名,綁定控制器名,因為這里是單一模塊,確實可以這樣做,但是控制器不唯一,所以點到為止。 - 我理想的訪問最簡單的就是網址后面加一個方法名就能看到頁面,即ServerName/方法名。所以接下來在application/route.php文件下面加上一條配置: ``` "login"=>"index/login/login" ``` 然后我就可以直接用方法名訪問登錄界面了:<http://127.0.0.1:8081/login> ,由于thinkphp路由的唯一性,只要寫了這條配置,你再訪問http://127.0.0.1:8081/index/login/login 反而會報錯呢,在這里留心一下就可以了。 - 其實這個url我還是覺得不是很舒服,我想現在就看到網址加方法名的效果,[比如說thinkphp.com/login](http://xn--thinkphp-jo1ot97lz3ze.com/login) ,沒問題,這都是小事。 - 打開D:/wamp64/bin/apache/apache2.4.18/conf/extra/httpd-vhosts.conf,就是上面的那個文件,再加上一段代碼:(看到端口號又變成了80端口,ServerName變成了 [thinkphp.com](http://thinkphp.com)) ``` <VirtualHost *:80> ServerName thinkphp.com DocumentRoot D:/wamp64/www/tp5/public <Directory "D:/wamp64/www/tp5/public/"> Options +Indexes +FollowSymLinks +MultiViews AllowOverride All Require local </Directory> </VirtualHost> ``` - 再用編輯器打開C:\\Windows\\System32\\drivers\\etc\\hosts,在最下方加上一條127.0.0.1 [thinkphp.com](http://thinkphp.com),保存,重啟apache - [http://thinkphp.com/login,](http://thinkphp.com/login%EF%BC%8C) 我再在瀏覽器中輸入就能訪問到登錄界面了 . - 但是這里你會發現,無論是輸入輸入密碼錯誤,或者是輸入驗證碼錯誤,都跳轉不回登錄界面,并且就算你密碼跟驗證碼都輸入對了,還是不行,憋著急,都是簡化URl惹的禍,我帶你改幾個地方就好了(找到問題就好解決,既然跳轉不行,就找有跳轉的地方): 首先:controller/Login.php的logining方法改為,對比前后看變化 ``` public function logining() { $name = input('request.name'); $password = input('request.password'); $data = input('request.captcha'); if(!captcha_check($data)){ //驗證失敗 return $this->error("驗證碼錯誤","location:/login"); }; $check=\app\index\model\Admin::login($name, $password); if ($check) { header(strtolower("location:/admin")); exit(); }else{ return $this->error("用戶名或密碼錯誤","location:/login"); } } ``` 然后就OK啦。 ### 總結: - 現在你可以訪問http://127.0.0.1:8081/login 或者http://thinkphp.com/login 訪問到你的登錄界面,另外我再補充幾個路由配置,在route.php里面: ``` <?php /**** @author:1132w11 2016.10.25 14:02; ****/ return [ '__pattern__' => [ 'name' => '\w+', ], '[hello]' => [ ':id' => ['index/hello', ['method' => 'get'], ['id' => '\d+']], ':name' => ['index/hello', ['method' => 'post']], ], "login"=>"index/login/login", //登錄頁面 "logining"=>"index/login/logining", //登錄頁面 "/"=>"index/index/index", //默認首頁 "admin"=>"index/admin/admin", //后臺頁面 "changepsw"=>"index/admin/changepsw", //修改密碼頁面 "logout"=>"index/admin/logout", //退出登錄 "changepassword"=>"index/admin/changepassword", //修改密碼 ]; ``` 這里要保證方法名的唯一性。簡單一點就是每個控制器每個方法都要寫一遍!后面再優化這個route.php 溫馨提示:在每一個跳轉動作的時候,一定要注意路徑中前面的斜杠"/"是否要加,如果加了斜杠導致跳轉不過去或者報錯,嘗試去掉一下!項目中跳轉主要出現在a標簽的url、form表單提交的action還有success跟error判斷處。
                  <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>

                              哎呀哎呀视频在线观看