Laravel first day of learning (creating laravel projects, routes, views, blade Templates), laravelblade_php tutorials

Source: Internet
Author: User

Laravel the first day of learning (creating laravel projects, routes, views, blade templates), Laravelblade


Create a Laravel Project

composer Create-project Laravel/laravel learnlv 4.1.* View Help: Composer Create-projectUse the Artisan tool to 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

http://www.bkjia.com/PHPjc/957480.html www.bkjia.com true http://www.bkjia.com/PHPjc/957480.html techarticle Laravel first day of learning (create Laravel project, route, view, Blade template), Laravelblade create Laravel project composer Create-project Laravel/laravel LEARNLV 4.1.* View Help: ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.