[Laravel] Laravel的根本使用
Jun 13, 2016 pm 12:29 PM
[Laravel] Laravel的基本使用
[Laravel] Laravel的基本HTTP路由
?
使用Laravel的基本路由,實(shí)現(xiàn)get請(qǐng)求響應(yīng),找到文件app/Http/routes.php
調(diào)用Route的靜態(tài)方法get(),實(shí)現(xiàn)get響應(yīng),參數(shù):string類型的路徑,匿名函數(shù)function(){}
匿名函數(shù)內(nèi)部,返回string數(shù)據(jù)
?
實(shí)現(xiàn)post,put,delete的請(qǐng)求,同上
?
實(shí)現(xiàn)get傳遞參數(shù)的路由,調(diào)用Route的靜態(tài)方法get(),參數(shù):路徑,匿名函數(shù)
路徑,大括號(hào)包裹參數(shù)名,不含$,例如:’/user/{id}’
匿名函數(shù),接收參數(shù),例如:function($id){}
?
[Laravel] Laraval的基本控制器
?
在app/Http/Controllers目錄下,新建一個(gè)Index/IndexController.php
定義命名空間,namespace App\Http\Controllers\Index
引入Controller基本控制器,use App\Http\Controllers\Controller
定義IndexController繼承Controller
實(shí)現(xiàn)方法index,返回?cái)?shù)據(jù)
定義路由指定控制器的行為,例如:Route::get("/index","Index\[email?protected]");,
注意命名空間部分,新建的控制器是在根命名空間下面,指定的時(shí)候添加自己新加的命名空間
?
[Laravel] Laravel的基本視圖
在目錄resources/views/下面,創(chuàng)建index/index.php
在控制器中使用函數(shù)view()來調(diào)用模板,參數(shù):文件路徑(.分隔目錄),數(shù)據(jù)
?
路由:routes.php
?
<span style="color: #000000;">php</span><span style="color: #008000;">/*</span><span style="color: #008000;">|--------------------------------------------------------------------------| Routes File|--------------------------------------------------------------------------|| Here is where you will register all of the routes in an application.| It's a breeze. Simply tell Laravel the URIs it should respond to| and give it the controller to call when that URI is requested.|</span><span style="color: #008000;">*/</span><span style="color: #008000;">/*</span><span style="color: #008000;">測(cè)試get post</span><span style="color: #008000;">*/</span><span style="color: #000000;"> Route::get(</span>'/'<span style="color: #000000;">, function () { $url</span>=url("index"<span style="color: #000000;">); </span><span style="color: #0000ff;">return</span> "Hello World"<span style="color: #000000;">.$url; </span><span style="color: #008000;">//</span><span style="color: #008000;">return view('welcome');</span><span style="color: #000000;">});Route::post(</span>"/post"<span style="color: #000000;">,function(){ </span><span style="color: #0000ff;">return</span> "測(cè)試post"<span style="color: #000000;">;});</span><span style="color: #008000;">/*</span><span style="color: #008000;">傳遞參數(shù)</span><span style="color: #008000;">*/</span><span style="color: #000000;">Route::get(</span>"/user/{id}"<span style="color: #000000;">,function($id){ </span><span style="color: #0000ff;">return</span> "用戶"<span style="color: #000000;">.$id;});</span><span style="color: #008000;">/*</span><span style="color: #008000;">使用控制器</span><span style="color: #008000;">*/</span><span style="color: #000000;">Route::get(</span>"/index","Index\[email?protected]"<span style="color: #000000;">);</span><span style="color: #008000;">/*</span><span style="color: #008000;">|--------------------------------------------------------------------------| Application Routes|--------------------------------------------------------------------------|| This route group applies the "web" middleware group to every route| it contains. The "web" middleware group is defined in your HTTP| kernel and includes session state, CSRF protection, and more.|</span><span style="color: #008000;">*/</span><span style="color: #000000;">Route::group([</span>'middleware' => ['web'<span style="color: #000000;">]], function () { </span><span style="color: #008000;">//</span>});
?
控制器:IndexController.php
?
<span style="color: #000000;">phpnamespace App\Http\Controllers\Index;use App\Http\Controllers\Controller;</span><span style="color: #0000ff;">class</span> IndexController <span style="color: #0000ff;">extends</span><span style="color: #000000;"> Controller{ </span><span style="color: #0000ff;">public</span><span style="color: #000000;"> function index(){ $data</span>=<span style="color: #000000;">array(); $data[</span>'title']="Index控制器"<span style="color: #000000;">; </span><span style="color: #0000ff;">return</span> view("index.index"<span style="color: #000000;">,$data); }}</span>
?
模板:index.php
<span style="color: #0000ff;"><span style="color: #800000;">body</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="container"</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="content"</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="title"</span><span style="color: #0000ff;">></span><span style="color: #0000ff;"></span><span style="color: #ff00ff;">php echo $title;</span><span style="color: #0000ff;">?></span><span style="color: #0000ff;"></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"></span><span style="color: #800000;">body</span><span style="color: #0000ff;">></span></span></span></span></span>
?

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? PHP ??? ??? ??? ?? ???? ??? ?? ????? ???????. Laravel? ?? ??? ???? ??? ? ? ???? ??? ??? ???? ?????? ?? ? ?? ?? ???? ?????. Symfony? ? ???? ??? ???? ?????. Codeigniter? ??? ??? ?? ??? ?? ??? ?? ????? ?????. 2. AI ??? ???? ????? ??? ??? ??, ???? ?? ?? (? : ???, ??, F1 ?), ??? ? ?? ?? ? ?? ??? ?? ???? ?? ??? ???? ???? ?? ??? ? ?? ???? ?? ?? ??? ????? ?? ???? ????? ?????? ??? ????? ???????. 3. ??? ?? ?? ????? ?? ??? ?????. AES? ?? ??? ???? ????? ?????.

PHP?? ?? ??? ???? ? ?? ?? ??? ????. 1. php.ini? ?? ??? ??; 2. ? ?? (? : Apache? Setenv ?? nginx? FastCGI_Param)? ??????. 3. PHP ?????? putenv () ??? ??????. ? ??? Php.ini? ????? ??? ???? ??? ???? ? ?? ??? ?? ???? ????? ???? Putenv ()? ?? ??? ?????. ?? ???? ?? ?? (? : php.ini ?? ? ?? ??)? ???? ????. ?? ?? ??? ??? ?? ??? ????? ???? ?? ????.

PHP ????? ?? ??? ??? ? ??? ??? CI (Continuous Integration) ????? ???? ? ????. 1. DockerFile? ???? ?? ???, ?? ??, ??? ?? ? ?? ??? ???? PHP ??? ?????. 2. Gitlabci? ?? CI/CD ??? ???? .gitlab-ci.yml ??? ?? ??, ??? ? ?? ??? ???? ?? ??, ??? ? ??? ?????. 3. PHPUNIT? ?? ??? ??? ??? ???? ?? ?? ? ???? ???? ????????. 4. Kubernetes? ?? ?? ?? ??? ???? ?? .yaml ??? ?? ?? ??? ?????. 5. Dockerfile ??? ? ??? ??? ??????

PHP ??? ?? ???? ????? ??? ??, ??? ??, ?? ? ?? ?? ???? ???????. ??, ??? ?? ???? ???? JWT? ???? ??? ??? ??????. ??, ??? ?? ????? ? ?????? ??? ???? ?? ???? ?????. ??, Alipay ?? WeChat ??? ???? ???? ??? ?????. ??, ?? ?? ??? ?? ??? ??? ??? ?????. Laravel ??? ??? ???? ?? ???? ?????, ?? ?? ? ??? ??? ???? ??? ??? ????, ??? ????? ??, ??????, ?? ? ?? ??? ?????? ??? ??? ??????? ??? ? ??? ???????.

??? ??? ??? ?? AI? ??? PHP? ?? ????? PHP? ??? "???"?????, ?? ???? ????? ???? ??? ? ??, ASYNCHRONOUS ??? ?? AI ??? (? : Google CloudVideoAi ?)? ??????? ????. 2. PHP? JSON ??? ?? ????, ??, ??, ??, ?? ? ?? ??? ???? ??? ??? ???? ??????? ?????. 3. ??? PHP? ??? ? ???? ???? ?? PHP ?????? ????? ????? ???? ? ??? AI ??? ???? ???? ????. 4. ???? ???? ??? ?? ?? (?? ?? ? URL??? ???? ????? ?? ??), ??? ?? (??? ??? ??), ?? ?? (??? ??, ?? ????) ? ?? ??? (?? ???)? ?????. 5. ??? ??? ????? ?? ?????

??? ?? ??? PHP ???? ?? ?? ??? ???? ?? ???????. RBAC (Role-Based Access Control) ??? ?? ???, ?? ? ??? ???? ??? ?? ?? ? ??? ?????. ?? ???? ??? ?????. 1. ???, ?? ? ??? ? ???? user_roles ? role_permissions? 3 ?? ?? ???; 2. $ user-> can ( 'edit_post')? ?? ???? ?? ?? ??? ?????. 3. ??? ???? ??? ??????. 4. ?? ??? ???? ?? ?? ?? ? ??? ? ???? ???? ?? ??? ? ?? ??? ?????. 5. ??? ??? ?? ?? ???? ?? ???? "??"? ??????.

Laravel? eloquentscopes? ?? ??? ??? ??? ?????? ?? ?? ??? ????? ?????. 1. ?? ??? ???? ???? ???? ???? Post :: published (); 2. ??? ??? ?? ??? ???? ???? ?? ??? ?? ?? ?? ??? ???? ???? ??? ?????? ??? ???? ???????. 3. ????? ?? ?? ?? ??? ??? ?? ?? ??? ?? ? ? ??? ?? ? ? ?? ?? ??? ?????. 4. ?? ??? ? ??? ?? ???? ? ??? ? ?? ??, ?? ??, ?? ???? ? ?? ?????????.

Laravel? ?? ??? ?? ?? ??? ?? ?? ??? ???? ??? ??????. ?? ???? ?? ??? ????? ? ???? I/O ?? ? ?? ?? ??? ???? ???? ??? ?? ? ????. 1. ?? ????? ?? ? ? ???????? ??? ????? ?? ???? ??????. 2. ??? ? ??? ?? ? ? PhPartisAnconfig? ?? ???????. 3. ?? ??? ??? ??? ???? ?? ?? ?? ???? ???? ????. 4. ?? ?? ??? ???? ?? ??? ??? .env ??? ???? ?? ???????.
