Laravel學習第一天(建立laravel項目、路由、視圖、blade模板),laravelblade_PHP教程

來源:互聯網
上載者:User

Laravel學習第一天(建立laravel項目、路由、視圖、blade模板),laravelblade


建立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

http://www.bkjia.com/PHPjc/957480.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/957480.htmlTechArticleLaravel學習第一天(建立laravel項目、路由、視圖、blade模板),laravelblade 建立laravel項目 composer create-project laravel/laravel learnlv 4.1.* 查看協助:...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.