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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] ## 導入自定義的配置如 ``` // Conf/config.php // 自動加載 Conf/user.php 和 Conf/ email.php return array( 'LOAD_EXT_CONFIG' => 'user,email', ); ``` ## RESTFul APi 接口 [參考文檔](http://www.hmoore.net/manual/thinkphp/1879) >如果某控制器為純接口形式,則也可繼承該方法,而無需設置 在模塊名/userController 控制器中 創建繼承RestController的方法 ``` class UserController extends RestController{ protected $allowMethod = array('get','post','put','delete'); // REST允許的請求類型列表 protected $allowType = array('html','xml','json'); // REST允許請求的資源類型列表 Public function index(){ switch($this->_method){ case 'get': //todo $this->response(array('name'=>'cpj','age'=>12),'json',200); break; case 'put': //todo $this->response(array('name'=>'cpj','age'=>12),'json',200); break; case 'post': //todo $this->response(array('msg'=>'提交成功'),'json',200); break; case 'delete': //todo $this->response(array('msg'=>'刪除成功'),'json',200); break; } } } ``` 在data/Conf/config.php 中添加 路由映射 ``` 'URL_ROUTER_ON'=>true, 'URL_ROUTE_RULES'=>[ 'imapp/dept'=>array('api/dept/dept_list_redis'), ], ``` 訪問 `delete` 形式方法 `http://www.mapi.com/user/2` 則提示刪除成功 ## 生成靜態緩存 > [查考文檔](http://www.hmoore.net/manual/thinkphp/1839) 在模塊或commom /Conf/config.php中配額, ``` return array( 'HTML_CACHE_ON' => true, // 開啟靜態緩存 'HTML_CACHE_TIME' => 60, // 全局靜態緩存有效期(秒) 'HTML_FILE_SUFFIX' => '.html', // 設置靜態緩存文件后綴 'HTML_CACHE_RULES' => array( // 定義靜態緩存規則 '*'=>array('{:module}/{:controller}/{:action}/{$_SERVER.REQUEST_URI|md5}'),//生成的文件路徑,只要注意同樣一個頁面生成的路徑一樣即可 ) ); ``` 生成靜態文件后,如果存在靜態文件,則提前與調用操作方法 ``` public function show(){ echo "hello word"; //存在靜態緩存,則hello word 不會輸出 //todo $this->display(); } ``` ## 生成Lite 文件,提升網站性能 1. 在入口文件 `index.php` `define('BUILD_LITE_FILE',true);` 2. 替換框架入口文件 ``` require './ThinkPHP/ThinkPHP.php'; // 改成 require 'Application/Runtime/lite.php'; //即在index.php 中引入lite 文件即可. ``` 3. 通過 `index.php` 訪問即可 ## 使用 trace ``` 'SHOW_PAGE_TRACE' =>true, //開啟 //輸出trace trace($_GET,'用戶信息'); //顯示 用戶信息:Array ( [p_reload] => 1 [reload_time] => 1524811491619 [bookcate] => 1 ) ``` ## 表單令牌 > 防止表單的重復提交 在`模塊名/Conf/tags.php`中 ``` return array( // 添加下面一行定義即可 'view_filter' => array('Behavior\TokenBuild'), // 如果是3.2.1以上版本 需要改成 // 'view_filter' => array('Behavior\TokenBuildBehavior'), ); ``` 添加配置參數 `'TOKEN_ON' => true, // 是否開啟令牌驗證 默認關閉` 驗證 ``` $User = D("User"); // 生成模型類的驗證 if (!$User->create($_POST)){ // 令牌驗證錯誤 } ``` ## Widget擴展 > 常用于需要在模版的foreach 循環中在進行復雜操作 ``` //創建home/widget/DemoWidget.class.php namespace Home\Widget; use Think\Controller; class DemoWidget extends Controller{ public function menu($param1,$param2){ //方式1. 直接刪輸出 return [$param1, $param2,]; //只能是數組索引才會被list //方式2.支持模版 $menu = M('Cate')->getField('id,title'); $this->assign('menu',$menu); $this->display('Cate:menu'); // Cate/menu.html /* <foreach name="menu" item="title"> {$key}:{$title} </foreach> */ } } //在home/view/index/index.html中 <php> list($name,$param) = W('demo/menu',[['name'=>'cpj'],['age'=>23,'user'=>'hello']]); //w函數數組的形式傳參 dump($name); dump($param); </php> ``` ## cli模式(命令行模式) 推薦使用絕對路徑的形式 在`index.php`中添加`__DIR__` ``` define('APP_PATH',__DIR__.'/../Application/'); // 引入ThinkPHP入口文件 require __DIR__.'/../ThinkPHP/ThinkPHP.php'; ``` 1. 無參運行 `php index.php cli/index/demo` 2. 有參數運行-參數可寫在方法的參數中 `php index.php statis/index/demo/name/cpj/age/12` ## 子域名部署 ``` 'APP_SUB_DOMAIN_DEPLOY' => 1, // 開啟子域名配置 'APP_SUB_DOMAIN_RULES' => array( 'admin' => 'Admin', //admin.demo.com 'test' => 'Test', //test.demo.com ), ``` ## block 模板繼承 > [手冊](http://www.hmoore.net/manual/thinkphp/1800) 基礎模板 ```html <head> <meta charset="utf-8"> <block name="style"></block> </head> <html> <body> <div class="main-content"> <block name="main">文章內容(這段注釋會被覆蓋掉) </block> </div> <block name="script"></block> </body> <html/> ``` 繼承 ```html <extend name="Public/base" /> <block name="style"> <!--針對這個頁面的css,link等--> </block> <block name="main"> <!--針對這個頁面的內容--> </block> <block name="script"> <!--寫正對這個頁面的 script--> </block> ``` ## 概念D() 函數,使 IDE識別 Model 的方法 baseModel.class.php ``` class baseModel { protected static $_single; public static function DD() { $className = get_called_class(); if(!class_exists($className)){ return new \Think\Model(); } $className = substr($className,strripos($className,'\\')+1,-5); $formatStr = preg_replace("/([A-Z])/", ",\\1", $className); $wordList = explode(',', $formatStr); array_shift($wordList); $tableName = ''; foreach($wordList as $word){ $tableName .= strtolower($word).'_'; } $tableName = trim($tableName,'_'); if(!isset(self::$_single[$tableName]) || empty(self::$_single[$tableName])){ $obj = self::$_single[$tableName] = new static(); }else{ $obj = self::$_single[$tableName]; } if(empty(self::$_single[$tableName]->tableName)){ //新代碼不會再model中定義tableName,所以要在這里定義,以便im_app使用 self::$_single[$tableName]->tableName = $tableName; } return $obj; } } ``` 新的model 繼承 baseModel,在其他控制器中使用 ``` UserModel::DD(); ```
                  <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>

                              哎呀哎呀视频在线观看