■
View_Employee_Index
<?php class 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(); } } }
confirm.twig
<form method = "post" name = "form1" action = "http://localhost/fuelphp-1.7.3/public/employee/regist"> <h2>確認画面です</h2> <p>名字 :<input type="hidden" name ="family_name" value = {{family_name}}>{{family_name}}</p> <p>なまえ :<input type="hidden" name ="given_name" value = {{given_name}}>{{given_name}}</p> <p>名字カナ :<input type="hidden" name ="phonetic_of_family_name" value = {{phonetic_of_family_name}}>{{phonetic_of_family_name}}</p> <p>なまえカナ :<input type="hidden" name="phonetic_of_given_name" value = {{phonetic_of_given_name}} > {{phonetic_of_given_name}}</p> {{validation}} <tr > <input type="hidden" name ="bu" value = {{bu}}>{{bu}}部</input> <input type="hidden" name ="ka" value = {{ka}}>{{ka}}課</input> <input type="hidden" name ="kakari" value = {{kakari}}>{{kakari}}係</input> </tr> <br> <tr> <input type="hidden" name ="yakushoku" value = {{yakushoku}}> 役職:{{yakushoku}}</p> </tr> <p><input type="submit" value="登録!"></p> <a href="" onclick="document.form1.submit();return false;">登録画面へ戻る</a> </form>
regist.twig
<form method="post" action = "http://localhost/fuelphp-1.7.3/public/employee/confirm"> <h2>フォームに入力してください。</h2> <p>名字 :<input type="text" name ="family_name" value = {{family_name}}></p> <p>なまえ :<input type="text" name ="given_name" value = {{given_name}}></p> <p>名字カナ : <input type="text" name ="phonetic_of_family_name" value = {{phonetic_of_family_name}}></p> <p>なまえカナ:<input type="text" name="phonetic_of_given_name" value = {{phonetic_of_given_name}} ></p> {{val_result}} <tr > <select name="bu"> {% for key, item in bu_list %} {% if bu == item.department_name %} <option value={{item.department_name}} selected>{{item.department_name}}</option> {% else %} <option value={{item.department_name}}>{{item.department_name}}</option> {% endif %} {% endfor %} </select> 部 <select name="ka"> {% for key, item in ka_list %} {% if ka == item.section_name %} <option value={{item.section_name}} selected>{{item.section_name}}</option> {% else %} <option value={{item.section_name}} >{{item.section_name}}</option> {% endif %} {% endfor %} </select> 課 <select name="kakari"> {% for key, item in kakari_list %} {% if kakari == item.subsection_name %} <option value={{item.subsection_name}} selected>{{item.subsection_name}}</option> {% else %} <option value={{item.subsection_name}} >{{item.subsection_name}}</option> {% endif %} {% endfor %} </select> 係 </tr> <br> <tr> <select name="yakushoku"> {% for key, item in yakushoku_list %} {% if yakushoku == item.assigned_name %} <option value={{item.assigned_name}} selected>{{item.assigned_name}}</option> {% else %} <option value={{item.assigned_name}}>{{item.assigned_name}}</option> {% endif %} {% endfor %} </select> </tr> 役職 <p><input type="submit" value="確認画面へ"></p> </form>
index.twig
<head> <title>社員システム</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 %}
View_Employee_Index
<?php class View_Employee_Index extends ViewModel { private $per_page = 3; public function view() { //ページネーションの設定 $count = Model_Employee::count(); $config = array( 'pagination_url' => 'employee', 'uri_segment' => 2, 'num_lijnks' => 4, 'per_page' => $this->per_page, 'total_items' => $count, ); //ページネーションObj生成 $pagination = Pagination::forge('employee_pagination', $config); //値取得 $this->result = Model_Employee::query() ->order_by('id', 'desc') ->limit($this->per_page) ->offset($pagination->offset) ->get(); foreach($this->result as $row){ $this->id = $row['id']; } $this->a = 'aaaaaaa'; } }
View_Employee_Confirm
<?php class View_Employee_Confirm extends ViewModel { public function view() { $result = Input::post(); $this->family_name = Input::post('family_name', null); $this->given_name = Input::post('given_name', null); $this->phonetic_of_family_name = Input::post('phonetic_of_family_name', null); $this->phonetic_of_given_name = Input::post('phonetic_of_given_name', null); $this->bu = Input::post('bu', null); $this->ka = Input::post('ka', null); $this->kakari = Input::post('kakari', null); $this->yakushoku = Input::post('yakushoku', null); } }
Controller_Detail
<?php class Controller_Detail extends Controller_Rest { public function post_detail() { $value = \Input::post('employee_id'); $result = Model_Employee::find($value, array('select' => array('picture_url', 'comments'))); return $this->response($result); } }
View_Employee_Done
<?php class View_Employee_Done extends ViewModel { public function view() { $result = Input::post(); $this->family_name = Input::post('family_name', null); $this->given_name = Input::post('given_name', null); $this->phonetic_of_family_name = Input::post('phonetic_of_family_name', null); $this->phonetic_of_given_name = Input::post('phonetic_of_given_name', null); $this->bu = Input::post('bu', null); $this->ka = Input::post('ka', null); $this->kakari = Input::post('kakari', null); $this->yakushoku = Input::post('yakushoku', null); } }
おつかれー