2020-1-11 lavarel7学习笔记
一、下载安装
下载符合php版本最新
composer create-project —prefer-dist laravel/laravel blog
指定版本安装
composer create-project —prefer-dist laravel/laravel blog 7.3.*
二、隐藏入口文件
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
</IfModule>
三、路由匹配、控制器、传参
\mylaravel\routes
内核:mylaravel\vendor\laravel\framework\src\Illuminate
1、路由匹配
Route::gen(‘/product/lists’,function(){
echo ‘aaaa’;
});
//访问:http://lv.php.com/product/lists
//输出:aaaa
Route::get(‘/product/detail/{id}/{iidd}’,function($id,$iidd){
if($id==22){
echo ‘this is product detail:华为手机’;
}
if($id==33){
echo ‘this is product detail:华为电视’;
}
echo ‘<br>价格:’.$iidd.’元’;
});
//访问:http://lv.php.com/product/detail/22/55
//输出:this is product detail:华为手机
价格:55元
控制器:
class Article extends Controller
{
public function lists(){
echo “这是文章列表”;
}
}
路由:Route::get(‘/product/detail/‘,’Article@lists’);
四、经验:
1、学习的时候语言的时候,一般建议的版本是最新版本-1或-2;
2、Laravel7和Laravel8区别在路由的写法上,其他的基本没变。比如:
laravel7:Route::get(‘/article/index’,’article@index’);
laravel8:Route::get(‘/article/index’,[Article::class,’index’]);