51
Laravel 프레임워크로 10분안에 블로그 만들어 보기 @findstar 안정수 Facebook Modern PHP Group XECon + PHPFest 2014 2014.11.08 Session 3-3

XECON2014 Laravel 프레임워크 소개

  • Upload
    js-ahn

  • View
    1.738

  • Download
    8

Embed Size (px)

DESCRIPTION

2014 XECON + PHPFEST 에서 발표한 Laravel 프레임워크 소개입니다.

Citation preview

Page 1: XECON2014 Laravel 프레임워크 소개

Laravel 프레임워크로

10분안에 블로그 만들어 보기

@findstar 안정수

Facebook Modern PHP Group

XECon + PHPFest 20142014.11.08 Session 3-3

Page 2: XECON2014 Laravel 프레임워크 소개

1. 발표 소개

2. Laravel 프레임워크란?

3. Laravel 의 이슈 원인

4. Laravel 의 주요 핵심

5. 10분 블로그 코딩

6. 마치며

부제 : Laravel 소개

+

10분 블로그 라이브 코딩

2014.11.08 Session 3-3 XECon + PHPFest 2014

Page 3: XECON2014 Laravel 프레임워크 소개

1. 발표 소개 - 발표자

- 계기

- 프레임워크

2. Laravel 프레임워크란?

3. Laravel 의 이슈 원인

4. Laravel 의 주요 기능

5. 10분 블로그 코딩

6. 마치며

2014.11.08 Session 3-3 XECon + PHPFest 2014

Page 4: XECON2014 Laravel 프레임워크 소개

Introduce

4

안정수 육아에 시달리고 있는 딸바보 개발자PHP, JAVA, Objective-C최근까지 전세계 날씨 분석 시스템을 만들었습니다.

@findstar

XECon + PHPFest 20142014.11.08 Session 3-3

Page 5: XECON2014 Laravel 프레임워크 소개

I need a framework

5

XECon + PHPFest 20142014.11.08 Session 3-3

1. 최신의 웹 개발 트렌드를 잘 녹여낸 프레임워크

2. 장기적으로 전망있는

3. 최신 PHP 버전에서 사용 가능한

Page 6: XECON2014 Laravel 프레임워크 소개

PHP frameworks

6

2014.11.08 Session 3-3 XECon + PHPFest 2014

Codeigniter

Zend

cakePHP

Fuelphp

Yii

Symfony

Laravel

Slim

Page 7: XECON2014 Laravel 프레임워크 소개

1. 발표 소개

2. Laravel 프레임워크란? - Laravel

- 목적

- 인기도

3. Laravel 의 이슈 원인

4. Laravel 의 주요 기능

5. 10분 블로그 코딩

6. 마치며

2014.11.08 Session 3-3 XECon + PHPFest 2014

Page 8: XECON2014 Laravel 프레임워크 소개

Laravel• 2011~ now version 4.2• Free, open-source• MVC framework• MIT License.• Full-stack framework• laravel.com

8

XECon + PHPFest 20142014.11.08 Session 3-3

Taylor Otwell

Page 9: XECON2014 Laravel 프레임워크 소개

Objectives

9

XECon + PHPFest 2014

즐거운 창의적인 엘레강스

2014.11.08 Session 3-3

Page 10: XECON2014 Laravel 프레임워크 소개

Popularity

2014년 가장 유망한 프레임워크

10

XECon + PHPFest 2014

2013.12.28 sitepoint

1 Laravel

2 Phalcon

3 Symfony2

4 Codeigniter

http://www.sitepoint.com/best-php-frameworks-2014/

2014.11.08 Session 3-3

#1

25.85%

Page 11: XECON2014 Laravel 프레임워크 소개

11

XECon + PHPFest 2014

since August 2014

Github 가장 인기 있는 PHP 프로젝트

Most popular and watched Project

Popularity

12,913

2014.11.08 Session 3-3

#2

Page 12: XECON2014 Laravel 프레임워크 소개

12

XECon + PHPFest 2014

Popularity구글 트렌드 (from 2004 to current)

구글 트렌드 링크

2014.11.08 Session 3-3

#3

Page 13: XECON2014 Laravel 프레임워크 소개

1. 발표 소개

2. Laravel 프레임워크란?

3. Laravel 이슈 원인 - Modern

- Full stack

- Easy to learn

4. Laravel 의 주요 기능

5. 10분 블로그 코딩

6. 마치며

2014.11.08 Session 3-3 XECon + PHPFest 2014

Page 14: XECON2014 Laravel 프레임워크 소개

#0 Modern PHP

• OOP - Design Pattern• MVC• Composer• Autoloading• PSR• Testable

14

XECon + PHPFest 20142014.11.08 Session 3-3

2014 NOMAD PHP EU

2013 9월 PHP 5.5 Web summit

Ben RamseyPHP contributor

Page 15: XECON2014 Laravel 프레임워크 소개

#1 Laravel• OOP• Composer• Autoloading• Namespace• PSR-0, PSR-4, PSR-1• Testable• php 5.4

15

XECon + PHPFest 20142014.11.08 Session 3-3

Page 16: XECON2014 Laravel 프레임워크 소개

#2 Extendable

16

XECon + PHPFest 2014

SSH

URL

Redis

EventDB

Crypt

Cookie

Session

Cache

Schema

ViewQueue

Auth

Mail Log

File

Panigator

Input

Hash

Validator

Form

HTML

Route

Lang

Request Response

Redirect

2014.11.08 Session 3-3

Page 17: XECON2014 Laravel 프레임워크 소개

#2 Extendable

17

XECon + PHPFest 20142014.11.08 Session 3-3

Google App EngineAmazon EC2

FortrabbitPagoda Boxdigital ocean

HerokuLinode

OpenShift

ElixirGulp

BowerAngularJS

Env controllerVagrantEnboy

HomestedDeploy

Front-endCloud Devel

Page 18: XECON2014 Laravel 프레임워크 소개

#3 Easy To Learn

18

XECon + PHPFest 2014

= 해치지 않아요

= 물지 않아요

어렵지 않아요

2014.11.08 Session 3-3

Page 19: XECON2014 Laravel 프레임워크 소개

#3-1 Good Documents, APIS

19

XECon + PHPFest 2014

laravel.com/docs/installationlaravel.com/api

2014.11.08 Session 3-3

Page 20: XECON2014 Laravel 프레임워크 소개

#3-2 Laracasts

20

XECon + PHPFest 2014

• 200여개의 동영상 강의

• 데일리 업데이트

• 라라벨, PHP, IDE, ENV• 유료, 무료 강의 제공

2014.11.08 Session 3-3

Page 21: XECON2014 Laravel 프레임워크 소개

#3-3 Cool Community

21

XECon + PHPFest 2014

링크드인 페이스북 구글 플러스

공식 포럼 Freenode #Laravel laravel.kr

2014.11.08 Session 3-3

Page 22: XECON2014 Laravel 프레임워크 소개

#3-4 Elegant Syntax

$userName = Input::get('userName'); Route::controller('products', 'ProductController'); Session::put('key', 'value'); Mail::send('sign.welcome', $data, $callback); $value = Cache::get('key');

22

XECon + PHPFest 20142014.11.08 Session 3-3

Page 23: XECON2014 Laravel 프레임워크 소개

1. 발표 소개

2. Laravel 프레임워크란?

3. Laravel 이슈 원인

4. Laravel 의 주요 기능 - MVC

- Request Cycle

- IoC Container

- Artisan CLI

5. 10분 블로그 코딩

6. 마치며

2014.11.08 Session 3-3 XECon + PHPFest 2014

Page 24: XECON2014 Laravel 프레임워크 소개

MVC Framework• Model : Eloquent ORM

• View : Blade Template

• Control : RESTful Controller

24

XECon + PHPFest 20142014.11.08 Session 3-3

Page 25: XECON2014 Laravel 프레임워크 소개

MVC Flow

25

XECon + PHPFest 2014

RouteController

Request

Response

Model

View

WEBSERVER

2014.11.08 Session 3-3

Page 26: XECON2014 Laravel 프레임워크 소개

Request Cycle

26

XECon + PHPFest 2014

Phase 4. run

Phase 1. Autoloading

Phase 2. Application Set

Phase 3. bootstrap

composer autoloading

serviceprovider file path

user config route resonse

2014.11.08 Session 3-3

Page 27: XECON2014 Laravel 프레임워크 소개

IoC Container

27

XECon + PHPFest 2014

Inversion Of Control클래스 의존성을 관리하는 강력한 도구

DI - 의존성 삽입(Dependency injection)을 통해서

하드코딩된 클래스간 의존성을 제거하는 하나의 방법

대신에 클래스의 의존성은 런타임시에 삽입되어

강력한 유연성을 제공하게 되고, 이로 인해

의존성 구현이 쉽게 변경될 수 있게 됨을 이야기 합니다.

2014.11.08 Session 3-3

Page 28: XECON2014 Laravel 프레임워크 소개

Artisan CLI• Laravel 에서 제공하는 Command Line

Interface• 주요 코드 generation, cache,

queue 컨트롤등의 역활을 수행

28

XECon + PHPFest 20142014.11.08 Session 3-3

Page 29: XECON2014 Laravel 프레임워크 소개

SImple MVC Code

29

XECon + PHPFest 2014

# in app/route.php

Route::get('user/{id}', 'UserController@showProfile');

# in app/controllers/UserController.php

class UserController extends BaseController {

public function showProfile() { $user = User::find($id);

return View::make('user.profile', array('user' => $user)); }

}

# use app/views/user/profile.blade.php

2014.11.08 Session 3-3

Page 30: XECON2014 Laravel 프레임워크 소개

1. 발표 소개

2. Laravel 프레임워크란?

3. Laravel 이슈 원인

4. Laravel 의 주요 기능

5. 10분 블로그 코딩 - Install

- Routing

- Controller

- Model

- View

6. 마치며

2014.11.08 Session 3-3 XECon + PHPFest 2014

Page 31: XECON2014 Laravel 프레임워크 소개

10분 블로그 만들기

31

XECon + PHPFest 20142014.11.08 Session 3-3

Page 32: XECON2014 Laravel 프레임워크 소개

내가 이걸 왜 한다고 했을까

32

XECon + PHPFest 20142014.11.08 Session 3-3

Page 33: XECON2014 Laravel 프레임워크 소개

Live Coding 준비

33

XECon + PHPFest 20142014.11.08 Session 3-3

Page 34: XECON2014 Laravel 프레임워크 소개

Blog• Post - CRUD

• Bootstrap CSS

• MariaDB

34

XECon + PHPFest 20142014.11.08 Session 3-3

Page 35: XECON2014 Laravel 프레임워크 소개

Installation #1

35

XECon + PHPFest 2014

composer create-project laravel/laravel myproject --no-dev --prefer-dist

2014.11.08 Session 3-3

Page 36: XECON2014 Laravel 프레임워크 소개

Installation #2• app/storage 폴더의 권한 변경$ chmod -R 777 app/storage

• app/config 설정database 연결 설정 app/config/database.php

• debug 설정 개발을 용이하게 하기 위해서 debug 설정 app/config/app.php

36

XECon + PHPFest 20142014.11.08 Session 3-3

Page 37: XECON2014 Laravel 프레임워크 소개

Installation #3• scaffolding 을 위한 composer 추가 • faker seeding 을 위한 faker 추가composer.json 에서 require-dev 추가

“require-dev” : { “way/generators”: “~2.0” ,"fzaninotto/faker": "1.4.0" },

• composer udpate —dev -vvv composer.json 수정후 설치

• service provider 추가 app/config/app.php ‘Way\Generators\GeneratorsServiceProvider', 추가

37

XECon + PHPFest 20142014.11.08 Session 3-3

Page 38: XECON2014 Laravel 프레임워크 소개

Installation #3• composer udpate —dev -vvv composer.json 수정후 설치

• service provider 추가 app/config/app.php #service provider ‘Way\Generators\GeneratorsServiceProvider', 추가

38

XECon + PHPFest 20142014.11.08 Session 3-3

Page 39: XECON2014 Laravel 프레임워크 소개

App run$ php artisan serve

: 내장 서버를 활용해서 웹서버를 구동해줍니다.

39

XECon + PHPFest 20142014.11.08 Session 3-3

Page 40: XECON2014 Laravel 프레임워크 소개

Artisan scaffolding• Artisan CLI scaffolding

40

XECon + PHPFest 20142014.11.08 Session 3-3

php artisan generate:scaffold post

--fields="title:string, body:text"

Page 41: XECON2014 Laravel 프레임워크 소개

Routing 등록

• 라우팅 룰 등록 기본

41

XECon + PHPFest 20142014.11.08 Session 3-3

Route::resource('posts', 'PostsController');

Page 42: XECON2014 Laravel 프레임워크 소개

Route Rule$ php artisan route

42

XECon + PHPFest 20142014.11.08 Session 3-3

Page 43: XECON2014 Laravel 프레임워크 소개

PostsController# in app/controllers/PostsController.php

class PostsController extends \BaseController {

public function index() {} // /posts GET public function create() {} // /posts/create GET public function store() {} // /posts POST public function show($postId){} // /posts/{postId} GET public function edit($postId){} // /posts/{postId}/edit GET public function update($postId){} // /posts/{postId} PUT|PATCH public function destroy($postId){} // /posts/{postId} DELETE

}

43

XECon + PHPFest 20142014.11.08 Session 3-3

Page 44: XECON2014 Laravel 프레임워크 소개

Models# in app/models/Post.php

44

XECon + PHPFest 20142014.11.08 Session 3-3

class Post extends \Eloquent { protected $guarded = ['id']; }

Page 45: XECON2014 Laravel 프레임워크 소개

View<!doctype html> <html> <head> <meta charset="utf-8"> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css"/> </head> <body> <div class="container"> <div class="row"> <div class="col-md-6 col-md-offset-3"> @yield('content') </div> </div> </div> </body></html>

45

XECon + PHPFest 20142014.11.08 Session 3-3

master.blade.php

Page 46: XECON2014 Laravel 프레임워크 소개

Live Coding!

46

XECon + PHPFest 20142014.11.08 Session 3-3

Page 47: XECON2014 Laravel 프레임워크 소개

제약1. 국내의 다수 호스팅에서는 안되요. PHP 5.4 이상부터 사용 가능

2. 한글 자료가 많이 없어요

-> 시간이 약.

3. 국내에서 사례가 있나요? -> 아직 뚜렷한 레퍼런스는 없습니다.

4. 느리지 않나요? -> 코드 이그나이터 보다 느립니다. phalcon 보다는.. 엄청 느립니다. -> 대신 개발 생산성을 이야기 합니다.

47

XECon + PHPFest 20142014.11.08 Session 3-3

Page 48: XECON2014 Laravel 프레임워크 소개

One More Thing

48

XECon + PHPFest 20142014.11.08 Session 3-3

Page 49: XECON2014 Laravel 프레임워크 소개

laravel.kr

49

XECon + PHPFest 20142014.11.08 Session 3-3

Page 50: XECON2014 Laravel 프레임워크 소개

Q&A

50

XECon + PHPFest 20142014.11.08 Session 3-3

Page 51: XECON2014 Laravel 프레임워크 소개

51

XECon + PHPFest 2014

감사합니다.

2014.11.08 Session 3-3