Laravel first day of learning (creating laravel projects, routes, views, blade Templates)
Create a Laravel Project
Composer Create-project Laravel/laravel LEARNLV 4.1.*
View Help: Composer Create-project
Using the Artisan tool
Generate key:php Artisan key:genrate, more commands see: Http://blog.luoyunshu.com/laravel-cheatsheet
Routing
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 layout
(master.blade.php):
@include('layout.header')
@yield('content')
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
Code Packaging:
Http://files.cnblogs.com/files/luoyunshu/learnlv.zip
-
1 floor cheung son love game
-
two times development using Laravel