내 결과가 모두 만들어지고 편집되고 저장되는 곳에서 Laravel PHP 응용 프로그램을 실행 중입니다. 이제 사용자가 범주를 선택할 수있는 드롭 다운 상자가있는 기능을 추가하고 사용자가 드롭 다운 상자에서 선택하는 내용에 따라 결과가 홈 페이지에 표시됩니다.Laravel PHP : 결과를 표시하기 위해 드롭 다운 상자 사용
이 작업을 수행하는 방법에 대한 몇 가지 문서를 찾으려고했지만 가능한 유일한 해결책은 jQuery와 함께 AJAX를 사용하여 결과를 업데이트하는 것입니다. 나는 이것을하기의 더 쉬운, 우아한 방법이 있는지 생각해보고있다.
보기 :
@section('content')
/* New section I recently added for including the dropdown box below */
<div class="row">
<div class="panel panel-default">
<div class="panel-heading clearfix">
<b>{{'Select a category' }}</b>
</div>
<div class="panel-body">
<dl class="dl-horizontal">
<div class="table-responsive">
<table class="table">
<tr>
<td>
{{Form::open(array('route' => 'select_vids_pics', 'files' => true)) }}
<div class="form-group">
/* Form Code goes here, 'label' and 'select options' */
<div class="form-group">
{{ Form::submit('Select Category', array('class' => 'btn btn-primary')) }}
</div>
{{ Form::close() }}
</div>
</td>
</tr>
</table>
</div>
</dl>
</div>
</div>
</div>
/* Blocks of code below for currently display all results */
<div class="row">
<div class="panel panel-default">
<div class="panel-heading clearfix">
<b>{{'Overview of Videos' }}</b>
</div>
<div class="panel-body">
@if ($allvids->count())
<dl class="dl-horizontal">
<!-- Add this div class to make the table responsive -->
<div class = "table-responsive">
<table class="table">
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>Edge</th>
<th>Stone</th>
<th>Category</th>
<th>Project</th>
<th>Update Video</th>
</tr>
@foreach($allvids as $video)
<tr>
<td>{{ $video->video_id }}</b></td>
<td>{{ $video->video_name }}</td>
<td>{{ $video->video_description }}</td>
<td>{{ $video->video_edges }} </td>
<td>{{ $video->video_stones }}</td>
<td>{{ $video->category }}</td>
<td>{{ $video->video_project }}</td>
<td><b>{{ link_to_route("show_video", 'Edit', array($video->video_id)) }}</b></td>
</tr>
@endforeach
{{ $allvids-> links()}}
</table>
</div>
</dl>
@else
<b>{{ 'All Pics Vids' }}</b>
@endif
</div>
</div>
</div>
<div class="row">
<div class="panel panel-default">
<div class="panel-heading clearfix">
<b>{{'Overview of Pictures' }}</b>
</div>
<div class="panel-body">
@if ($allpics->count())
<dl class="dl-horizontal">
<!-- Add this div class to make the table responsive -->
<div class = "table-responsive">
<table class="table">
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>Edge</th>
<th>Stone</th>
<th>Category</th>
<th>Project</th>
<th>Update Picture</th>
</tr>
@foreach($allpics as $picture)
<tr>
<td>{{ $picture->picture_id }}</b></td>
<td>{{ $picture->picture_name }}</td>
<td>{{ $picture->picture_description }}</td>
<td>{{ $picture->picture_edges }} </td>
<td>{{ $picture->picture_stones }}</td>
<td>{{ $picture->category }}</td>
<td>{{ $picture->picture_project }}</td>
<td><b>{{ link_to_route("show_picture", 'Edit', array($picture->picture_id)) }}</b></td>
</tr>
@endforeach
{{ $allpics-> links()}}
</table>
</div>
</dl>
@else
<b>{{ 'All Pics Vids' }}</b>
@endif
</div>
</div>
</div>
@stop
컨트롤러 :로부터
1) 수락 입력 :
/* This is the only function that is being used in the view above */
public function index()
{
$allvids = Video::paginate(10);
$allpics = Picture::paginate(10);
$this->layout->content = \View::make('home.pics_vids_overview', array('allvids' => $allvids, 'allpics' => $allpics));
}
내가 내 컨트롤러에 다른 함수/메소드를 추가해야합니까 드롭 다운 상자에서 사용자가 선택한 2) 해당 입력을 새롭게 정의 된 함수를 찾아서 그 결과에 따라 결과를 표시 하시겠습니까?
위의 방법을 사용하면 함수가 다음과 같이 보일까요?
public function pics_vids_categories()
{
$input = \Input::all();
$videos = DB::table('videos')->where('category', '=', $input)->get();
$pictures = DB::table('pictures')->where('category', '=', $input)->get();
var_dump($videos);
var_dump($pictures);
}
내가 말했듯이, 나는 이것을하는 더 예쁜 방법이 있기를 바라고 있습니다.
저는 완전히 대답하기에 Laravel에 익숙하지는 않지만 Zend Framework에서는 제가 교체 한 부분만을 렌더링하는 뷰 스크립트를 가지고있을 것이고 Ajax 요청에 엘리먼트로 반환 될 것입니다. JSON 문자열. – Sonny