Laravel View, Controller & Template
Laravel View, Controller & Template
[app/routes.php]
Route::get('users', 'UserController@getIndex'); /* /users 로 넘어오는 경우, UserController의 getIndex 호출. */
[app/controllers/UserController.php]
layout->content = View::make('user.profile', array('hello' => 'world')); } }
[app/views/layouts/v1.blade.php]
@section('sidebar') hihi This is the master sidebar. @show @yield('content')
[app/views/user/profile.blade.php]
@section('sidebar') @parent This is appended to the master sidebar. @stop @section('content') This is my body content. {{ $hello }} @stop
한번 봐 둬야 할 부분.
Controller에서 layout을 직접 지정한다. $this->layout. protected로 해 두는것이 적당한 듯.
layouts.v1 은 views/ layouts/v1 .blade.php 와 대응한다. user.profile 은 views/ user/profile .blade.php 와 대응한다. a.b.c 는 views/a/b/c.blade.php 와 대응한다.
.blade.php 와 대응한다. blade 라는 나름의 마크업을 쓰는 모양. @section('...') (@parent) ... @stop 이 기본적으로 익혀두면 좋겠다.
http://laravel.com/docs/templates#blade-templating
View에 데이터를 전달하기 - http://laravel.com/docs/responses
통상적으로는
View::make('greeting', array('name' => 'Taylor'));
와 같은식으로 처리하면 되는듯 하고,
$view = View::make('greeting')->nest('child', 'child.view', $data);
와 같이 $child 에 child.view + $data 를 넣어서 greeting에서 사용 가능하게 할 수 있다.
View Composer - http://tb.chan.je/493 : 같은 View를 불러오는 경우에 변수 등을 미리 정의해 둘 수 있다. View에 데이터를 넘길 때 전처리 과정을 쉽게 할 수 있도록 도와준다.
JSON 처리 - http://laravel.com/docs/responses#special-responses
Creating A JSON Response return Response::json(array('name' => 'Steve', 'state' => 'CA'));
Creating A JSONP Response return Response::json(array('name' => 'Steve', 'state' => 'CA'))->setCallback(Input::get('callback'));
Creating A File Download Response return Response::download($pathToFile); return Response::download($pathToFile, $name, $headers);
Routes 는 다음 포스트에서...
from http://ejnahc.tistory.com/492 by ccl(A) rewrite - 2020-03-06 13:21:01
댓글
댓글 쓰기