2014-04-09 3 views
2

Laravel 프레임 워크와 블레이드 템플릿 엔진을 사용하고 있습니다.버튼을 클릭하여 리디렉션

내보기에 2 개의 버튼이 있습니다. 클릭하면 다른보기로 리디렉션됩니다. 내가 노력 코드이었다

<button type="button" onclick="{{ Redirect::to('users.index') }}">Button</button> 

답변

6

당신이 (블레이드 템플릿에서 가정이 코드) 시도 할 수 있습니다 : 그러나

<button type="button" onclick="window.location='{{ url("users/index") }}'">Button</button> 

{{ url('users/index') }}이 때문에 url 인쇄를하여도 같은이 될 것입니다 브라우저에서이 :

:

<button type="button" onclick="window.location='http://domain.com/users/index'">Button</button> 

그것은 당신이 경로 이런 식으로 뭔가를 선언 한 것을 의미한다 이 경우

Route::get('users/index', array('uses' => '[email protected]', 'as' => 'users.index')); 

도 사용할 수있다 : 풋 아웃

<button type="button" onclick="window.location='{{ route("users.index") }}'">Button</button> 

은 동일합니다. 왜 당신이 할 수있는 내가 볼 수 없지만

<button type="button" onclick="window.location='{{ URL::route('users.index'); }}'">Button</button> 

:

1

그래, 당신은 기본적으로 (단지 대신 PHP 도우미의 http://yoursite.com/users 같은 것을 넣어 동일) URL을 생성하는 URL 도우미를 사용해야합니다 버튼 대신 'href'태그를 사용하면됩니다.

<a href="{{ URL::route('users.index'); }}">My button</a> 
관련 문제