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

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                Base 類簡化方法完成全局輸入變量的檢測、獲取和安全過濾 下面列出的實現方法兼容Thinkphp5框架寫法 [TOC] ## 1.檢測變量是否設置 ``` $this->has('id','get'); $this->has('name','post'); $this->has('name');//自動判斷類型 ``` > 目前支持變量類型: 'param', 'get', 'post', 'request', 'env', 'route' ## 2.變量獲取 > 變量類型方法('變量名/變量修飾符','默認值','過濾方法') 獲取輸入變量的時候,可以支持默認值,例如當URL中不包含$_GET['name']的時候,使用下面的方式輸出的結果比較。 ``` $this->get('name'); // 不存在返回值為null $this->get('name',''); // 返回值為空字符串 $this->get('name','Jack'); // 返回值為Jack ``` #### (1)獲取PARAM變量 PARAM類型變量是框架提供的用于自動識別當前請求的一種變量獲取方式,是系統推薦的獲取請求參數的方法,用法如下: ``` $this->param('name'); // 獲取當前請求的name變量 $this->param(); // 獲取當前請求的所有變量(經過過濾) $this->param(false); // 獲取當前請求的所有變量(原始數據) ``` > param方法會把當前請求類型的參數和路由變量以及GET請求合并,并且路由變量是優先的。 > (route路由參數變量-->請求類型參數(post|put|patch)-->GET請求參數) #### (2) 獲取route路由變量 route方法是通過$this->getRequest()->getParams()獲取當前請求中的所有路由參數 ``` $this->route('name'); // 獲取當前請求的name變量 $this->route(); // 獲取當前請求的所有變量(經過過濾) $this->route(false); // 獲取當前請求的所有變量(原始數據) ``` #### (3)獲取GET變量 ``` $this->get('id','1'); // 獲取某個get變量,默認值可選 $this->get('name'); // 獲取get變量 $this->get(); // 獲取所有的get變量(經過過濾的數組) $this->get(false); // 獲取所有的get變量(原始數組) //獲取get變量 并且不進行任何過濾 即使設置了全局過濾 $this->get('name','',null); ``` #### (2)獲取POST變量 ``` $this->post('name'); // 獲取某個post變量 $this->post(); // 獲取經過過濾的全部post變量 $this->post(false); // 獲取全部的post原始變量 ``` #### (3)獲取PUT變量 ``` $this->put('name'); // 獲取某個put變量 $this->put(); // 獲取全部的put變量(經過過濾) $this->put(false); // 獲取全部的put原始變量 ``` #### (4)獲取REQUEST變量 > 先路由參數中尋找參數name,如果沒有找到的話,將從POST, GET, Cookie, Server中尋找;區分大小寫 ``` $this->request('id'); // 獲取某個request變量 ``` #### (5)獲取SERVER變量 ``` $this->server('PHP_SELF'); // 獲取某個server變量 $this->server(); // 獲取全部的server變量 ``` 變量名不區分大小寫(會自動轉為大寫后獲取) #### (6)獲取ENV變量 同SERVER方法,也不區分大小寫 #### (7)獲取文件上傳信息 ``` $this->getFiles() ``` #### (8)獲取cookie參數|可過濾 $name 變量名 $default 默認值 $filter 過濾方法 ``` $this->cookie($name = '', $default = null, $filter = '') ``` ## 3.獲取部分變量 > 采用only方法能夠安全的獲取你需要的變量,避免額外變量影響數據處理和寫入。 如果你只需要獲取當前請求的部分參數,可以使用: 只獲取當前請求的id和name變量 ``` $this->only('id,name'); ``` 或者使用數組方式 , 只獲取當前請求的id和name變量 ``` $this->only(['id','name']); ``` 默認獲取的是當前請求參數(PARAM類型變量),如果需要獲取其它類型的參數,可以使用第二個參數,例如: 只獲取GET請求的id和name變量 ``` $this->only(['id','name'],'get'); ``` 只獲取POST請求的id和name變量 ``` $this->only(['id','name'],'post'); ``` ### 4.排除部分變量 也支持排除某些變量獲取,例如:排除id和name變量 ``` $this->except('id,name'); ``` 或者使用數組方式, 排除id和name變量 ``` $this->except(['id','name']); ``` * 同樣支持指定變量類型獲取: * 排除GET請求的id和name變量 ``` $this->except(['id','name'],'get'); ``` * 排除POST請求的id和name變量 ``` $this->except(['id','name'],'post'); ``` ### 5.變量修飾符 支持對變量使用修飾符功能,可以一定程度上簡單過濾變量,更為嚴格的過濾請使用下面提到的變量過濾功能。 用法如下: ``` $this->變量類型('變量名/修飾符'); ``` 如果需要傳入字符串之外的變量可以使用下面的修飾符,包括: 修飾符 作用 s 強制轉換為字符串類型 d 強制轉換為整型類型 b 強制轉換為布爾類型 a 強制轉換為數組類型 f 強制轉換為浮點類型 下面是一些例子: ``` $this->get('id/d'); $this->post('name/s'); $this->post('ids/a'); ``` > 如果你要獲取的數據為數組,請一定注意要加上 /a 修飾符才能正確獲取到。 ### 6.變量過濾 框架默認沒有設置任何過濾規則,可以是配置文件中設置全局的過濾規則: ``` default_filter ='htmlspecialchars' ``` > 也支持使用 $this 對象進行全局變量的獲取過濾,過濾方式包括函數、方法過濾,以及PHP內置的Types of filters,我們可以設置全局變量過濾方法,例如: ``` $this->filter('htmlspecialchars'); ``` 支持設置多個過濾方法,例如: ``` $this->filter(['strip_tags','htmlspecialchars']); ``` 也可以在獲取變量的時候添加過濾方法,例如: ``` $this->get('name','','htmlspecialchars'); // 獲取get變量 并用htmlspecialchars函數過濾 $this->param('username','','strip_tags'); // 獲取param變量 并用strip_tags函數過濾 $this->post('name','','org\Filter::safeHtml'); // 獲取post變量 并用org\Filter類的safeHtml方法過濾 ``` 可以支持傳入多個過濾規則,例如: ``` $this->param('username','','strip_tags,strtolower'); // 獲取param變量 并依次調用strip_tags、strtolower函數過濾 ``` $this對象還支持PHP內置提供的Filter ID過濾,例如: ``` $this->post('email','',FILTER_VALIDATE_EMAIL); ``` 框架對FilterID做了轉換支持,因此也可以使用字符串的方式,例如: ``` $this->post('email','','email'); ``` 采用字符串方式定義FilterID的時候,系統會自動進行一次filter_id調用轉換成Filter常量。 具體的字符串根據filter_list函數的返回值來定義。 需要注意的是,采用Filter ID 進行過濾的話,如果不符合過濾要求的話 會返回false,因此你需要配合默認值來確保最終的值符合你的規范。 例如, ``` $this->post('email','',FILTER_VALIDATE_EMAIL); ``` 就表示,如果不是規范的email地址的話 返回空字符串。 如果當前不需要進行任何過濾的話,可以使用(null) 獲取get變量 并且不進行任何過濾 即使設置了全局過濾 ``` $this->get('name','',null); ```
                  <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>

                              哎呀哎呀视频在线观看