laravel5 只能够使用根目录下的server.php访问,需要开启Apache下的mod_rewrite模块,才能正常使用。
关于去除public目录的问题,httpd.conf中 DocumentRoot "c:/wamp/www/" 改为 DocumentRoot "c:/wamp/www/app/public/",然后重启Apache
数据库连接文件修改注意,需要修改两处,分别为config/database.php , /.env两文件
composer create-project laravel/laravel laravelName --prefer-dist
路由请求方式分为五种:
1.基本路由
Route::get();
Route::post();
2.多请求路由
Route::match('get,post','multy'function(){
});
Route::any();
3.参数路由
Route::get('user/{id}',function($id){
return "user-".$id;
});
MVC目录位置以及使用方法:
model /app
view /app/reresources/views
controller /app/http/controller
返回根据控制器动作的重定向
return redirect()->action('App\Http\Controllers\HomeController@index');
return redirect()->action('App\Http\Controllers\UserController@profile', [1]);
return redirect()->action('App\Http\Controllers\UserController@profile', ['user' => 1]);
传值到view
return view('greeting', ['name' => 'James']);
传递数据到视图
// 使用传统的方法
$view = view('greeting')->with('name', 'Victoria');
// 使用魔术方法
$view = view('greeting')->withName('Victoria');
$view = view('greetings', $data);
关于去除public目录的问题,httpd.conf中 DocumentRoot "c:/wamp/www/" 改为 DocumentRoot "c:/wamp/www/app/public/",然后重启Apache
数据库连接文件修改注意,需要修改两处,分别为config/database.php , /.env两文件
composer create-project laravel/laravel laravelName --prefer-dist
路由请求方式分为五种:
1.基本路由
Route::get();
Route::post();
2.多请求路由
Route::match('get,post','multy'function(){
});
Route::any();
3.参数路由
Route::get('user/{id}',function($id){
return "user-".$id;
});
MVC目录位置以及使用方法:
model /app
view /app/reresources/views
controller /app/http/controller
返回根据控制器动作的重定向
return redirect()->action('App\Http\Controllers\HomeController@index');
return redirect()->action('App\Http\Controllers\UserController@profile', [1]);
return redirect()->action('App\Http\Controllers\UserController@profile', ['user' => 1]);
传值到view
return view('greeting', ['name' => 'James']);
传递数据到视图
// 使用传统的方法
$view = view('greeting')->with('name', 'Victoria');
// 使用魔术方法
$view = view('greeting')->withName('Victoria');
$view = view('greetings', $data);

本文介绍如何正确配置Laravel5项目以便于通过不同路径访问,并解释了Apache配置及数据库连接设置。此外,还详细介绍了Laravel5中的基本路由、多请求路由和参数路由的用法。
7042

被折叠的 条评论
为什么被折叠?



