Laravel学习第一天(创建laravel项目、路由、视图、blade模板)
创建laravel项目
composer create-project laravel/laravel learnlv 4.1.*
查看帮助:composer create-project
使用artisan工具
生成key:php artisan key:genrate,更多命令见:http://blog.luoyunshu.com/laravel-cheatsheet
路由
route.php:
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
//向控制器传递参数,Route::get('/{id}')
//两种格式:1、Route::get('/', function(){})
// 2、Route::get('/', array('as'=>'home_route',function(){})) as的定义路由名称
Route::get('/', array('as'=>'home_route', function()
{
//向视图传递参数
//方法一:
//$var = 'hello world';
//return View::make('hello')->with('va本文来源gaodai#ma#com搞*!代#%^码$网!搞代gaodaima码r', $var);
//方法二
//$var = 'abcd';
//return View::make('hello', array('var'=>$var));
//方法三
$var = 'def';
$view = View::make('index.hello');
$view->var = $var;
return $view;
}));
//定义控制器
Route::get('index', function()
{
$arr = array(
'yunshu',
'云舒'
);
return View::make('index.index', array('arr'=>$arr));
});
//生成路由URL与跳转