-
tp\thinkphp\Request.php文件有所以的請求方法 //獲取當前是哪個模塊\控制器\操作 再操作,用于調試 dump($request->module()); dump($request->controller()); dump($request->action()); dump($request->url());//當前.URL ./index/Index/index/type/5.html?id=10 dump($request->baseUrl());//不用?號后的參數查看全部
-
//獲取域名\路由\地址 use think\Request public function index(Request $request){ dump($request->domain());//http://jianpf.com dump($request->pathinfo());//index/index/index.html dump($request->path());//index/index/index //請求類型 dump($request->method());//GET請求 dump($request->isGet());//GET請求true dump($request->isPost());//POST請求true dump($request->isAjax());//AJAX請求true //獲取請求的參數 dump($request->get());//tp5開始get數組沒有了pathinfo等信息,只有參數的數組 dump($request->param());//方法名也放數組中 dump($request->post()); //使用session需要開啟session //tp\thinkphp\convent.php下的第198行session=>['auto_start'=>ture]和刪除session安全'httpponly'和'secure'配置 dump($request->session());//session('name','jianpf');session助手函數 dump($request->cookie());//cookie('email','[email protected]');cookie助手函數 dump($request-param('name'));//獲取單個值 dump($request->session('name'));//獲取單個值 dump($request->cookie('name'));//獲取單個值查看全部
-
tp\public\index.php tp\thinkphp\start.php tp\thinkphp\base.php namespace thinkphp;\\對應于tp\thinkphp\library App::run()->send();\\對應于tp\thinkphp\library\App.php //run()方法只執行一次 /** * 執行應用程序 * @access public * @param Request $request Request對象 * @return Response * @throws Exception */ public static function run(Request $request = null) { is_null($request) && $request = Request::instance(); try { $config = self::initCommon(); if (defined('BIND_MODULE')) { // 模塊/控制器綁定 BIND_MODULE && Route::bind(BIND_MODULE); } elseif ($config['auto_bind_module']) { // 入口自動綁定 $name = pathinfo($request->baseFile(), PATHINFO_FILENAME); if ($name && 'index' != $name && is_dir(APP_PATH . $name)) { Route::bind($name); } }查看全部
-
tp請求對象獲取 request()老忘記request和response //方法注入請求 public function index(Request $requests){dump($request)} 助手函數request();//返回的是個對象 使用use think\Request; $res=Request::instance();//放回的是哥對象查看全部
-
tp\application\index\controller\Index.php下添加方法 public function info($id){return "{$id}"} tp\application\conf\route.php文件定義路由 <? return ['news/:id'=>'index/index/info'] //tp\thinkphp\convention.php文件是否開啟路由 'url_routeion'=>true,//85行 'url_route_must'=>false//強制使用路由(靜態路由,必須有路由,否則報錯找不到) //啟用路由可以用url()函數返回路由URL地址 echo url('index/index/index',['id'=>10]).'<br/>' 輸出/index/Index/index/id/10 echo url('index/index/info',['id'=>10]).'<br/>' 輸出/news/10.html查看全部
-
tp\public\index.php入口文件指定默認模塊 define('BIND_MODULE','admin');//綁定admin模塊 define('BIND_MODULE','admin\index');//綁定admin模塊index.php文件(只能傳遞方法),URL:localhost\User\index會報錯admin\index.php中沒有User->index方法 //給網站添加API tp\public\api.php內容: <?php define("APP_PATH",__DIR__.'/../app/'); define("CONF_PATH",__DIR__.'/../conf/'); define("BIND_MODULE",'api');//tp\application\api\controller\index.php require(__DIR__.'/../thinkphp/stat.php'); tp\thinkphp\convention.php慣例配置的auto_bind_module=>true 就可以不用在入口文件define("BIND_MODULE",'api');//直接按照http://localhost/api.php的文件綁定模塊,不能訪問其他模塊查看全部
-
MAMP啟用Apache的隱藏入口文件URL重寫規則 \mamp\config\apache\httpd.conf文件 第130行 rewrite_module 打開LoadModule rewrite_module modules/mod_rewrite.so 第239行 網站的目錄地址下 AllowOverride None 改成 AllowOverride All 重啟MAMP服務器 URL重寫規則啟用tp\public\.htaccess文件重寫的,沒有就報錯Not Found查看全部
-
tp5的但入口文件,大廈的入口,由寶安指路 tp\public\index.php tp\application應用目錄 tp\conf全局配置目錄 tp\extend全局拓展配置目錄 tp\thinkphp\base.php基本配置文件 tp\thinkphp\start.php安全過濾查看全部
-
dump(\think\Env::get('status'));//獲取單個.env變量 tp\.env內容 status=dev//環境變量識別場景配置 (線上線下開發) //判斷開發環境 $res=Env::get('status','prod');//PHP_STATUS=prod標記 tp/application/conf/config.php內容: <?php //導入Env類(這里是重點...) use think\Env; return ['app_status'=>Env::get('app_status','dev')];//沒有就讀tp/application/conf/dev.php配置文件 dump(config());查看全部
-
//Env系統函數 use think\Env; $res=Env::get('email');//下標小寫 $res=Env::get('email不存在');//返回NULL值 $res=Env::get('email不存在','直接返回此值'); //Env支持點語法 $res=Env::get('database_hostname'); $res=Env::get('database.hostname'); //打印系統環境變量 dump($_ENY); //自定義系統環境變量 tp/.env內容 [email protected] database_hostname=localhost database_username=root database_password=root #分組等效 [database] hostname=localhost username=root password=root dump($_ENV['PHP_EMAIL'])//下標變大寫 //只輸出['PHP_EMAIL']=>string(15)查看全部
-
//實例化當前所給位置下的Yndex.php對象$a $a=new Yndex(); //調用Yndex.php對象的方法jpf(); return $a->jpf();查看全部
-
tp的::雙冒號是靜態方法 $res=Config::has('app_debug');//tp/thinkphp/convention.php慣例配置文件 tp\thinkphp\library\think\config.php /** * 檢測配置是否存在 * @param string $name 配置參數名(支持二級配置 .號分割) * @param string $range 作用域 * @return bool */ public static function has($name, $range = '') { $range = $range ?: self::$range; if (!strpos($name, '.')) { return isset(self::$config[$range][strtolower($name)]); } else { // 二維數組設置和獲取支持 $name = explode('.', $name, 2); return isset(self::$config[$range][strtolower($name[0])][$name[1]]); } }查看全部
-
tp\thinkphp\helper.php助手函數初始化文件 /** 判斷助手函數是否不存在用戶函數 */ if (!function_exists('config')) { /** * 獲取和設置配置參數 * @param string|array $name 參數名 * @param mixed $value 參數值 * @param string $range 作用域 * @return mixed */ function config($name = '', $value = null, $range = '') { if (is_null($value) && is_string($name)) { return 0 === strpos($name, '?') ? Config::has(substr($name, 1), $range) : Config::get($name, $range); } else { return Config::set($name, $value, $range); } } } //注意::Config是首字母大寫 Config::get('配置名'); config('配置名','配置值','配置作用域標記是否一樣'); config('?配置名值是否不為null');查看全部
-
config類和config助手函數 tp\thinkphp\library\think\Config.php文件 range()方法:設置配置參數的作用域 parse()方法:解析配置文件或內容 load()方法:加載配置文件(PHP格式) has()方法:檢測配置是否存在 get()方法:獲取 set()方法:設置 reset()方法:重置配置 1.加載助手類,并使用框架助手函數 use think\Config; $res=Config::get(); 2.全路徑指向類,并使用框架助手函數 $res=\think\Config::get(); 3.助手函數(不一定是框架助手類)$res=config(); dump($res);查看全部
-
動態配置config()函數 //01魔術方法:類自動加載方法 public function __construct(){config('before','beforeAction');//動態配置} //修改配置(簡單連接MYSQL數據庫) \think\Config::set('database.type','mysql');//連接MYSQL \think\Config::set('database.database','test');//數據庫名 \think\Config::set('database.username','root');//MYSQL用戶 \think\Config::set('database.prefix','');//表前綴 $data = ['字段1' => '值1', '字段2' => '值2']; $res=\think\Db::table('表名')->insert($data);//插入數據 dump($res); $res=\think\Db::table('表名')->select();//查詢數據 dump($res);查看全部
舉報
0/150
提交
取消