發表文章

目前顯示的是 9月, 2019的文章

[Linux]ll常用參數

指令:ls 或是 ll 檔名正向排序 ll -c 檔名反向排序 ll -r 指定排序條件 ll --sort=OOO extension 副檔名(ll -X) none (ll -U) size 檔案大小(ll -S) time 存取時間(ll -t) version 版本(ll -v) 檢視當前目錄下的檔案數量(不包含子目錄中的檔案) ll -l |grep "^-"|wc -l 檢視當前目錄下的檔案數量(包含子目錄中的檔案) 注意:R,代表子目錄 ls -lR|grep "^-"| wc -l

jQuery-Radio取值/選取

指定某個 radio button 被選取 (使用 prop ) <input type="radio" name="no" value="1">1<br> <input type="radio" name="no" value="2">2<br> <input type="radio" name="no" value="3">3<br> <button type="button" id="btn">選取2</button> $("#btn").on("click", function() { //方法1:指定value $("input[name='no'][value='2']").prop("checked", true); //方法2:指定位置 $("input[name='no']").eq(1).prop("checked", true); }); 取得 Radio 單選框選中的值 <input type="radio" name='myradio' value="1"> <input type="radio" name='myradio' value="2"> <input type="radio" name='myradio' value="3"> <button>Click</button> $("button").on("click", function(){

PHP-scandir()並取得目錄下檔案

圖片
scandir 回傳值是Array,回傳值的第一項是「.」,就是目前資料夾的意思,第二項是「..」也就是上一個資料夾,但是沒辦法像glob那樣指定到檔案格式 $arr_Scan = scandir('./'); 用scandir()印出結果 Array ( [0] => . [1] => .. [2] => .DS_Store [3] => .git [4] => FileInc [5] => SPD.spd [6] => config [7] => getFileTicket.php [8] => index.php [9] => readme.mk ) 列出目錄下檔案 function dirToArray($dir) { $result = array(); $cdir = scandir($dir); foreach ($cdir as $key => $value) { if (!in_array($value, array(".", ".."))) { if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) { $result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value); } else { $value = iconv("BIG5", "UTF-8", $value); $result[] = $value; } } } return $result; } 可以完整找出資料夾下的所有目錄與檔案. Array ( [0] => .DS_Store [.git] => Array ( [0] =>

Linux-vim常用設定

部分Linux安裝後只有vi可用,不過vim的功能還是比較強大,安裝指令: sudo apt-get install vim 移動到根目錄,並建立vim設定檔.vimrc cd ~; vim .vimrc 常用的設定 :set nu 顯示行數 :set ai 自動對齊縮排 :set bg=dark 上色模式 :set tabstop=4 縮排間格數 :set shiftwidth=4 自動縮排對齊間隔數 參考網址: 成大資工Wiki-vimrc設定教 學

GCP Deploy Laravel

Run Create a new Laravel project using the laravel installer. laravel new blog Go to the blog directory cd blog Run the app with the following command: php artisan serve Visit  http://localhost:8000  to see the Laravel Welcome page. Deploy Create an app.yaml file with the following contents: runtime: php72 env_variables: ## Put production environment variables here. APP_KEY: YOUR_APP_KEY APP_STORAGE: /tmp VIEW_COMPILED_PATH: /tmp SESSION_DRIVER: cookie Replace YOUR_APP_KEY in app.yaml with an application key you generate with the following command: php artisan key:generate --show Modify bootstrap/app.php by adding the following block of code before the return statement. This will allow you to set the storage path to /tmp for caching in production. # [START] Add the following block to `bootstrap/app.php` /* |-------------------------------------------------------------------------- | Set Storage Path |---------------------------------------------

GCP 安裝步驟

準備開始 先安裝 Cloud SDK 更新Components gcloud components update 新建專案 gcloud projects create [YOUR_PROJECT_NAME] --set-as-default 顯示所有專案 gcloud projects list 確認專案是否建立 gcloud projects describe [YOUR_PROJECT_NAME] 在專案下建立App gcloud app create --project=[YOUR_PROJECT_NAME] 選擇部屬地區  參考網址 地區 區域 位置 asia-east1 a、b、c 台灣彰化縣 asia-east2 a、b、c 香港 asia-northeast1 a、b、c 日本東京 asia-northeast2 a、b、c 日本大阪 asia-south1 a、b、c 印度孟買 asia-southeast1 a、b、c 新加坡裕廊西 australia-southeast1 a、b、c 澳洲雪梨 europe-north1 a、b、c 芬蘭哈米納 europe-west1 b、c、d 比利時聖吉斯蘭 europe-west2 a、b、c 英國倫敦 europe-west3 a、b、c 德國法蘭克福 europe-west4 a、b、c 荷蘭埃姆斯港 europe-west6 a、b、c 瑞士蘇黎世 northamerica-northeast1 a、b、c 加拿大魁北克省蒙特婁 southamerica-east1 a、b、c 巴西奧薩斯庫 (聖保羅) us-central1 a、b、c、f 美國愛荷華州康索布魯夫 us-east1 b、c、d 美國南卡羅來納州蒙克斯科納 us-east4 a、b、c 美國北維吉尼亞州阿什本 us-west1 a、b、c 美國奧勒岡州達勒斯 us-west2 a、b、c 美國加州洛杉磯 複製Helloworld到本機端測試 git clone https://github.com/GoogleCloudPlatform/php-docs-samples.git 進helloworl

Laravel-Controller基本介紹

controller的檔案會在app/Http/Controllers底下 RESTful 資源控制器  使用 make:controller Artisan 指令,我們可以快速地建立像這樣的控制器。先新增controller,在專案資料夾下指令 php artisan make:controller UserController --resource 基本操作 編輯app\Http\Controllers\UserController.php ... public function show($id) { return '編號:' . $id; } Route指定Contrller行為 Route::get('user/{id}', [UserController::class, 'show']);

Laravel-Views基本介紹

views在 resources/views 底下 新增Views  檔名user.blade.php,格式{名稱}.blade.php #View <!doctype html> <html> <head> <title>Laravel</title> </head> <body> <h1>{{$text}}, {{$name}}</h1> 工號 {{$erpid}} </body> </html> #route Route::get('/user/{id}', 'UserController@hello'); #Controller public function hello($id) { //方法1 return view( 'user', [ 'name' => 'Shock', 'erpid' => $id, 'text' => 'Welcome' ] ); //方法2 return view('user')->with('name', 'Shock')->with('erpid', $id)->with('text', 'Welcome'); }

Laravel-Middleware基本介紹

HTTP 中介層提供一個方便的機制來過濾進入應用程式的 HTTP 請求。Laravel 框架已經內建一些中介層,包括維護、身份驗證、CSRF 保護,等等。所有的中介層都放在 app/Http/Middleware 目錄內。 RESTful 資源控制器  要建立一個新的中介層,可以使用 make:middleware 這個 Artisan 指令: php artisan make:middleware OldMiddleware 全域使用(Global Middleware) protected $middlewarePriority = [ // //新增剛剛新增的OldMiddleware \Illuminate\Auth\Middleware\OldMiddleware::class, ]; 為 Route 指派 Middleware protected $routeMiddleware = [ // //新增剛剛新增的OldMiddleware 'old' => \Illuminate\Auth\Middleware\OldMiddleware::class, ]; Route使用中介層 //方法1 Route::get('admin/profile', function () { // })->middleware('auth'); //方法2 Route::middleware('auth')->get('admin/profile', function () { // }); //方法3 use App\Http\Middleware\OldMiddleware; Route::get('user/S2137', function () { // })->middleware(OldMiddleware::class); //方法4 Route::middleware('first', 'second')->get('user/S2137', function () {

Laravel-Route基本介紹

在web.php中有一個為根目錄(‘/’)且附帶閉包函數的預設路由。這個路由預設是使用者造訪根目錄時,就會回傳 welcome.blade.php 的內容。 Route::get('/', function () { return view('welcome'); }); 直接回傳 Route::get('/', function () { return 'Hello World'; }); 設定一個回傳foo的路由,可以透過 Route::get('foo', function () { return 'Hello World'; }); 或顯示 resource/views/about.blade.php Route::get('about', function () { return view('about'); }); Route方法 Route::get($uri, $callback); Route::post($uri, $callback); Route::put($uri, $callback); Route::patch($uri, $callback); Route::delete($uri, $callback); Route::options($uri, $callback); //使用部分動詞 Route::match(['get', 'post'], '/', function () { // }); //符合所有動詞,則使用any Route::any('foo', function () { // }); Route參數 Route::get('/user/{id}',function($id){ return 'user_id:'.$id; }); //預設參數值 Route::get('posts/{post}/comments/{comment}/type/{type?}', function (

Laravel-目錄結構

圖片
app目錄 包含應用程式的核心程式碼 bootstrap目錄 包含的檔案用來啟動框架和設定自動載入;以及包含一個 cache 資料夾,其中內有框架對效能最佳化所產生的檔案,例如 route 和 services 的快取檔案。 config目錄 config 目錄包含所有應用程式的配置檔案。 database目錄 包含資料庫遷移與資料填充檔案 public目錄 存放著 index.php 檔案,此檔案為應用程式的 HTTP 請求入口點。此目錄還包含了前端資源檔,如圖片、JavaScript 和 CSS。 resources目錄 resources 目錄包含你的視圖、原始的資源檔 (LESS、SASS、CoffeeScript) ,以及語言檔。 routes目錄 routes目錄 Laravel框架預設的路由文件web.php, api.php, console.php。 storage目錄 主要是存放編譯後的Blade模板、session、框架產生的檔案以及系統的log檔案。這個目錄需設定為可寫入的權限。 tests目錄 主要是laravel支援TDD開發模式,在這個目錄中包含了PHPUnit測試的相關文件會放在這邊。 vendor目錄 composer命令用的相關模組都會放在這邊 維護模式 啟動維護模式,這時候Laravel會載入 resources/views/errors/503.blade.php 這個模板顯示維護中。 php artisan down 關閉維護模式 php artisan up