<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之旅 廣告
                # 雜項 ## Seesion 使用`seesion`需要開啟初始化,中間件文件`middleware.php` ~~~php // session初始化 \think\middleware\SessionInit::class, ~~~ ~~~php class Store { public function session() { Session::set('user','mirror'); return Session::get('user'); } } ~~~ 使用`::set()`/`::get()`方法設置Session的存取 ~~~php Session::set('user','Mirror');//設置名稱user和值mirror Session::get('user'); //讀取user的session ~~~ > `::get()`的第二個參數可以設置默認值 > > `::all()`\=> 讀取全部的session 使用`Request`請求也可以獲取session: ~~~php Request::session('user');//讀取user的session Request::session(); //讀取全部的session ~~~ `::has()`判斷是否賦值 `::delete()`刪除session `::pull()`取值后刪除 `::clear()`清空整個seesion `::flash()`設置閃存數據,只請求一個有效的情況 * * * ## Cookie Cookie是在客戶端存儲,默認情況下開啟初始`config/cookie.php` 設置Cookie:`::set()` ~~~php Cookie::set('name','value',3600) ~~~ > 參數1:Cookie名稱 > > 參數2:Cookie值 > > 參數3:Cookie有效時間(秒) 長期存儲COOKIE:`::forever()` ~~~php Cookie::forever('name','value') ~~~ 獲取Cookie:`::get()``Request::cookie()` ~~~php Cookie::get('name'); Request::cookie('name'); ~~~ `::has()`判斷是否賦值 `::delete()`刪除session * * * ## 緩存功能-File 緩存配置文件`cache.php`,默認生成在`runtime/cache`目錄; `::set()`:設置一個緩存 `::has()`:判斷緩存是否存在 `::get()`:從緩存中獲取相應數據(無數據返回NULL) `::inc()`:自增 、`::dec`自減(可以設置步長) `::push()`:實現緩存的數組數據追加 `::delete()`:刪除指定的緩存文件 `::pull()`:獲取緩存值,然后刪除這個緩存 `::remember()`:如果數據不存在則寫入數據(可以依賴注入) `::clear()`:清除所有緩存 `::tag()`:可以將多個緩存歸類到標簽中,方便統一管理 ## 上傳功能 建立一個上傳表單: ~~~php <form action="Upload" enctype="multipart/form-data" method="post"> <input type="file" name="image"> <input type="submit" name="提交"> </form> ~~~ 在控制器類中創建一個`upload.php`,獲取上傳的數據: ~~~php class Upload { public function index() { // 獲取上傳的數據 $file = Request::file('image'); // 實現文件上傳并寫入指定目錄 $sevename = Filesystem::putFile('txt',$file); } } ~~~ > `Request::file()`:可以獲取文件上傳表單,生成一個FILE對象; > > `Filesystem::putFile()`:可以將FILE對象文件上傳到指定的目錄位置,配置文件`config/filesystem.php`;參數1:目錄名,參數2:FILE文件對象,參數3:上傳文件的命名規則(date、md5、sha1等)也支持自定義名規則; **多文件上傳**: ~~~php <form action="Upload" enctype="multipart/form-data" method="post"> <input type="file" name="image[]"><br> <input type="file" name="image[]"><br> <input type="file" name="image[]"><br> <input type="file" name="image[]"><br> <input type="submit" name="提交"> </form> ~~~ ~~~php class Upload { public function index() { // 獲取上傳的數據 $file = Request::file('image'); // 實現文件上傳并寫入指定目錄 $sevename = []; foreach($file as $files){ $sevename[] = Filesystem::putFile('txt',$files); } } } ~~~ **文件驗證**: 結合驗證器,針對上傳的文件進行驗證: | 驗證參數 | 說明 | | --- | --- | | fileSize | 上傳文件的最大字節 | | fileExt | 文件后綴,多個用逗號分割或者數組 | | fileMime | 文件MIME類型,多個用逗號分割或者數組 | | image | 驗證圖像文件的尺寸和類型 | ~~~php class Upload { public function index() { // 獲取上傳的數據 $file = Request::file('image'); // 驗證 $validate = Validate::rule([ 'image' => 'file|fileExt:jpg,png,gif' ]); $result = $validate->check([ 'image'=>$file ]); // 實現文件上傳并寫入指定目錄 if($result) { foreach ($file as $files) { $sevename = Filesystem::putFile('txt', $files); } dump($sevename); } else { dump($validate->getError()); } } } ~~~ ## 多語言 中間件文件`middleware.php`中開啟多語言切換功能 ~~~php \think\middleware\LoadLangPack::class ~~~ 配置文件`config/lang.php`文件,設置`zh-cn`中文語言 ## 驗證碼功能 驗證碼不是內置功能,需要composer引入: ~~~php composer require topthink/think-captcha ~~~ ~~~php <div>{:captcha_img()}</div> ~~~ > 支持點擊刷新 ~~~php <img src="{:captcha_src()}" alt="captcha"> ~~~ > 不支持點擊刷新 ~~~php class Upload { public function index() { $validate = Validate::rule([ 'captcha' => 'require|captcha' ]); $result = $validate->check([ 'captcha' => input('post.code') ]); if($result){ return '驗證碼輸入正確'; } else { return '驗證碼輸入錯誤'; } } } ~~~ | 參數 | 描述 | 默認 | | --- | --- | --- | | codeSet | 驗證碼字符集合 | 略 | | expire | 驗證碼過期時間(s) | 1800 | | math | 使用算術驗證碼 | false | | useZh | 使用中文驗證碼 | false | | zhSet | 中文驗證碼字符串 | 略 | | useImgBg | 使用背景圖片 | false | | fontSize | 驗證碼字體大小(px) | 25 | | useCurve | 是否畫混淆曲線 | true | | useNoise | 是否添加雜點 | true | | imageH | 驗證碼圖片高度,設置為0為自動計算 | 0 | | imageW | 驗證碼圖片寬度,設置為0為自動計算 | 0 | | length | 驗證碼位數 | 5 | | fontttf | 驗證碼字體,不設置是隨機獲取 | 空 | | bg | 背景顏色 | \[243, 251, 254\] | | reset | 驗證成功后是否重置 | true | > 配置文件`config/captcha.php` ### 分頁功能 模型操作和數據庫操作都可以使用`paginate()`方法實現: ~~~php return View::fetch('index',[ 'list' => User::paginate(5) ]); ~~~ ~~~html <table border="1"> <tr> <th>編號</th> <th>姓名</th> <th>性別</th> <th>郵箱</th> <th>價格</th> </tr> {volist name="list" id="user"} <tr> <td>{$user.id}</td> <td>{$user.username}</td> <td>{$user.gender}</td> <td>{$user.email}</td> <td>{$user.price}</td> </tr> {/volist} </table> ~~~ > 上述實現以五條數據顯示表格 ~~~html <style> .pagination { list-style: none; margin: 0; padding: 0; } .pagination li { display: inline-block; padding: 20px; } </style> <table border="1"> <tr> <th>編號</th> <th>姓名</th> <th>性別</th> <th>郵箱</th> <th>價格</th> </tr> {volist name="list" id="user"} <tr> <td>{$user.id}</td> <td>{$user.username}</td> <td>{$user.gender}</td> <td>{$user.email}</td> <td>{$user.price}</td> </tr> {/volist} </table> {$list|raw} <ul class="pagination"> ~~~ > 上述實現了分頁查詢按鈕的功能 默認情況下,生成的分頁輸出是完整分頁功能,帶總分頁數據和上下頁碼,分頁樣式只需要通過樣式修改即可,完整分頁默認生成的分頁輸出代碼為: ~~~html <ul class="pagination"> <li><a href="?page=1">&laquo;</a></li> <li><a href="?page=1">1</a></li> <li class="active"><span>2</span></li> <li class="disabled"><span>&raquo;</span></li> </ul> ~~~ 主要的分頁參數如下: | 參數 | 描述 | | --- | --- | | list\_rows | 每頁數量 | | page | 當前頁 | | path | url路徑 | | query | url額外參數 | | fragment | url錨點 | | var\_page | 分頁變量 | ## 圖像處理功能 不是系統內置功能 ~~~php composer require topthink/think-image ~~~ 創建圖像處理對象: ~~~php $image = Image::open('image.png') ~~~ 獲取圖像處理對象后,可以獲得各種屬性: ~~~php // 圖片寬度 $image->width(); // 圖片高度 $image->height(); // 圖片類型 $image->type(); // 圖片MIME $image->mime(); // 圖片大小 $image->size(); ~~~ 裁剪圖片:`crop()` ~~~php $image->crop(550,400)->save('crop1.png') ~~~ 使用`thumb()`方法,生成縮略圖 ~~~php $image->thumb(500,500)->save('thumb1.png') ~~~ 使用`rotate()`方法:旋轉圖片默認90度 ~~~php $image->rotate(180)->save('rotate1.png'); ~~~ 使用`water()`方法:給圖片添加水印默認位置右下角 ~~~php $image->water('mirror.png')->save('water1.png') ~~~ 使用`text()`方法:給圖片添加文字水印 ~~~php $image->text('mirror',getcwd().'/1.ttf',20,'#ffffff') ->save('text1.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>

                              哎呀哎呀视频在线观看