0419-2

list.js

$(document).ready(function() {$(document).ready(function() { console.log('afsdfas'); function sendParams(){ var per_page = $('option:selected').val() != null ? $('option:selected').val() : null; var keyword  = $('option:selected').val() != null ? $('option:selected').val() : null; var offset   = $('option:selected').val() != null ? $('option:selected').val() : null; var sort     = $('option:selected').val() != null ? $('option:selected').val() : null; var params = "per_page=" + per_page + "&keyword=" + keyword + "&offset=" + offset + "&sort=" + sort; // window.location.href = 'http://localhost/fuelphp-1.7.3/public/employee/index?' + params;  console.log(params); }});

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

ViewModel index.php

<?php<?phpclass View_Employee_Index extends ViewModel { private $per_page = 3; public function view() { //画面入力値の取得 $per_page = Input::get('per_page', 1); $keyword  = Input::get('keyword', null); $offset   = Input::get('offset', null); $sort     = Input::get('sort', 'id');
//ページネーションの設定 $count = Model_Employee::count(); $config = array( //'pagination_url' => 'employee', 'uri_segment' => 'page',//URL上のクエリパラメータの位置 'num_links' => 4, 'per_page' => $per_page, 'total_items' => $count, );
//ページネーションObj生成 $pagination = Pagination::forge('employee_pagination', $config); $this->pagination = $pagination;
//クエリ実行 $query = Model_Employee::query(); if(! empty($keyword)){ $query->where('id', $keyword); } //->where('id', $keyword)//ここ、後であいまい検索許容するよう修正 $this->result = $query->order_by($sort, 'desc') ->limit($this->pagination->per_page) ->offset($this->pagination->offset) ->get();
//値取得 //$this->result = Model_Employee::query()->get(); //->limit($this->per_page) //->offset($pagination->offset) // $this->result = Model_Employee::find('all',  // array( // 'related' => array( // // リレーションの設定名を指定 // 'affiliation', // 'position', // ), // ) // ); //var_dump($this->result); //役職 //部署表示用データ $affiliation_string = array(); $this->resultarray = array(); foreach($this->result as $row){ $this->resultarray[$row->id]['id'] = $row->id; $this->resultarray[$row->id]['family_name'] = $row->family_name; $this->resultarray[$row->id]['given_name'] = $row->given_name; $this->resultarray[$row->id]['phonetic_of_family_name'] = $row->phonetic_of_family_name; $this->resultarray[$row->id]['phonetic_of_given_name'] = $row->phonetic_of_given_name; $this->resultarray[$row->id]['assigned_name'] = $row->position->assigned_name; //各々の行ー>リレーション名ー>リレ先のカラム名 //var_dump($row->position); //部 //var_dump($row->affiliation->department_name); $affiliation_string =  $row->affiliation->department_name ? $row->affiliation->department_name .'部' : null; //課 $affiliation_string =   $row->affiliation->section_name ? $row->affiliation->section_name .'課' : null; //係 $affiliation_string[] = $row->affiliation->subsection_name ? $row->affiliation->subsection_name .'係' : null; //var_dump($affiliation_string); $this->resultarray[$row->id]['affiliation_result'] = implode( '', $affiliation_string);
//初期化 $affiliation_string = array(); } }}

 

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

index.twig

 

 

<head> <head> <title>It's unkoタイム</title>        <!-- JS -->        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>        <script src="http://localhost/fuelphp-1.7.3/public/assets/js/detail.js"></script>        <script src="http://localhost/fuelphp-1.7.3/public/assets/js/list.js"></script> </head> {% block content %}<form action="#" method="get" name="form" ><input type="search" name="search" placeholder="キーワードを入力"><div><input type="button" value="前のページへ戻る" onclick="sendParams();"></div><table border="1" width="600" cellspacing="0" cellpadding="5" bordercolor="#333333"><tr> <span class= "error"></span> <th bgcolor="#8EF1FF">ID</th> <th bgcolor="#8EF1FF">名字</th> <th bgcolor="#8EF1FF">名前</th> <th bgcolor="#8EF1FF">名字カナ</th> <th bgcolor="#8EF1FF">名前カナ</th> <th bgcolor="#8EF1FF">役職</th> <th bgcolor="#8EF1FF">部署</th>
</tr>
{% for item in resultarray %}<tr id = {{ item.id }} > <td class = "iddiv">{{ item.id }}</td> <td>{{ item.family_name}}</td> <td>{{ item.given_name }}</td> <td>{{ item.phonetic_of_family_name }}</td> <td>{{ item.phonetic_of_given_name }}</td> <td>{{ item.assigned_name }}</td> <td>{{ item.affiliation_result}}</td></tr> <tr ><td align="center" colspan = "7"><div "style= display:" >aaa</div></td></tr>{% endfor %}
</table><select name="per_page"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>
</form>{{ pagination|raw }} {{ random() }}{% endblock %}