创建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('var', $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与跳转
Route::get('test', function()
{
//生成URL
$url = URL::route('home_route');
//echo $url;
//跳转
return Redirect::route('home_route');
});
blade布局
(master.blade.php):
@include('layout.header')
<body>
<div>
<div>
@yield('content')
</div>
</div>
<div>
<div>
@section('section')
哈哈
@show
</div>
</div>
{{-- 注释代码--}}
@include('layout.footer')
index.blade.php:
@extends('layout.master')
{{-- 使用master模板 --}}
{{-- 使用这部分内容填充模板 --}}
@section('content')
@foreach($arr as $a)
{{ $a }}
@endforeach
{{-- 创建图片 --}}
{{ HTML::image('image/1.jpg') }}
@stop
{{-- 覆盖或者重写父模板内容 --}}
@section('section')
{{-- 拿到父模板的内容使用@parent --}}
@parent
'你好呀'
@stop
代码打包:
http://files.cnblogs.com/files/luoyunshu/learnlv.zip