您好,欢迎访问一九零五行业门户网

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('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')
@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
代码打包:
http://files.cnblogs.com/files/luoyunshu/learnlv.zip
以上就介绍了laravel学习第一天(创建laravel项目、路由、视图、blade模板),包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
其它类似信息

推荐信息