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);
	}
}
おつかれー

lang/ja

<?php
return array(
		'required'           => ':labelは必須です',
		'max_length'         => ':labelは:param:文字以内で入力してください',
		'correct_yakushoku'  => ':labelが所属と合致しません',
		'only_one_yakushoku' => '部署の役職人数制限に反します',
);

classes/validation.php

<?php
/**
 * 拡張Validation
 * 一括設定
 * @package     Fuel
 * @subpackage  Core
 * @category    Core
 */
class Validation extends \Fuel\Core\Validation
{
	// 検証条件をまとめて指定
	public function add_fieldset($params = array(), $input = array())
	{
		var_dump('aaaaaa');
		// 入力データが空ならPOSTを設定
		if ( count($input) <= 0 )
		{
			$input = $_POST;
		}
		var_dump($params);
		// 検証条件セット
		if( is_array($params) )
		{
			foreach($params as $conf)
			{
				if ( strlen($conf['rules']) > 0 )
				{
					$this->add_field($conf['name'], $conf['label'], $conf['rules']);
				}
			}
			return true;
		}
		return false;
	}

	// エラーをまとめて取得
	public function get_messages()
	{
		$msg = array();
		foreach($this->error() as $field => $error)
		{
			$msg[$field] = $this->error($field)->get_message();
		}
		return $msg;
	}
}

config/validation.php

<?php
return array(
	'employee' => array(
			'family_name'  => array(
				'name'   => 'name',
				'label'  => '名字',
				'rules'  => 'required|max_length[15]',
			),
			'given_name'  => array(
				'name'   => 'given_name',
				'label'  => '名前',
				'rules'  => 'required|max_length[15]',
			),
			'phonetic_of_family_name'  => array(
				'name'   => 'phonetic_of_family_name',
				'label'  => '名字(カナ)',
				'rules'  => 'required|max_length[15]',
			),
			'phonetic_of_given_name'  => array(
				'name'   => 'phonetic_of_given_name',
				'label'  => '名前(カナ)',
				'rules'  => 'required|max_length[15]',
			),
			'bu'  => array(
				'name'   => 'bu',
				'label'  => '部',
				'rules'  => 'required',
			),
			'yakushoku'  => array(
				'name'   => 'yakushoku',
				'label'  => '役職',
				'rules'  => 'required|correct_yakushoku|only_one_yakushoku',
			),
	),
);

Model_Employee

<?php

class Model_Employee extends \Orm\Model
{
	protected static $_properties = array(
		'id',
		'family_name',
		'given_name',
		'phonetic_of_family_name',
		'phonetic_of_given_name',
		'affiliation_id',
		'position_id',
		'picture_url',
		'comments',
		'has_been_deleted',
		'number_of_editing',
	);

	protected static $_table_name = 'employee';
	protected static $_belongs_to = array(
		'affiliation' => array(
			'key_from' => 'affiliation_id',
			'model_to' => 'Model_Affiliation',
			'key_to' => 'id',
		),
		'position' => array(
			'key_from' => 'position_id',
			'model_to' => 'Model_Position',
			'key_to' => 'id',
		)
	);

	/**
	 * 人数制限バリデーション用
	 */
	public function get_count_column($affi, $yakushoku){
		$query = self::forge();
		$query->where('affiliation_id', $affi)
		->where('position_id', '>', $yakushoku)
		->count();
		return $query;
	}
}

Cont/Emplo

<?php

class Controller_Employee extends Controller_Template
{

	private $per_page = 3;

	public function action_index()
	{
		//ビューに渡す配列の初期化
		$data = array();

		//タイトル
		$this->template->title = '社員情報一覧';
		//ビューの読み込み
		$this->template->content = ViewModel::forge('employee/index.twig');

	}

	public function get_regist()
	{
		 self::post_validation();
		//タイトル
		$this->template->title = '社員情報一覧';
		//ビューの読み込み
		$this->template->content = ViewModel::forge('employee/regist.twig');

	}
	//確認画面から戻ってくる用
	public function post_regist()
	{
		self::post_validation();
		//タイトル
		$this->template->title = '社員情報一覧';
		//ビューの読み込み
		$this->template->content = ViewModel::forge('employee/regist.twig');

	}

	public function post_confirm()
	{
		$validation = self::post_validation();
		var_dump($validation);
		//タイトル
		$this->template->title = '社員情報一覧';
		//ビューの読み込み
		$view = ViewModel::forge('employee/confirm.twig');
		$view -> set('validation', $validation);
		$this->template->content = ViewModel::forge('employee/confirm.twig');

	}

	public static function post_validation()
	{
		// プロファイリング停止
		Fuel::$profiling = false;

		// json初期値
		$json = array(
			'res'   => 'NG',
			'error' => array(),
		);

		// バリデーション設定
		Config::load('validation', true);
		$val_config = Config::get('validation.employee');

		$val = Validation::forge();
		$val->add_callable('Extension');
		$val->add_fieldset($val_config);
		var_dump($val->run());

		// バリデーションチェック
		if ( $val->run() )
		{
			$json['res'] = 'OK';
			$json['error'] = null;
		}
		else
		{
			$json['error'] = $val->get_messages();
		}
		return $json['error'];
	}
}

View_Employee_Regist

<?php
class View_Employee_Regist 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);

		//プルダウン表示用
		$bu_obj        = DB::select ( 'department_name' )->from ( 'affiliation' )->distinct(true)->execute();
		$ka_obj        = DB::select ( 'section_name' )->from ( 'affiliation' )->distinct(true)->execute();
		$kakari_obj    = DB::select ( 'subsection_name' )->from ( 'affiliation' )->distinct(true)->execute();
		$yakushoku_obj = DB::select ( 'assigned_name' )->from ( 'position' )->distinct(true)->execute();

		foreach ($bu_obj as $key => $value) {
			$bu_list[] =$value;
		}
		foreach ($ka_obj as $key => $value) {
			$ka_list[] =$value;
		}
		foreach ($kakari_obj as $key => $value) {
			$kakari_list[] =$value;
		}
		foreach ($yakushoku_obj as $key => $value) {
			$yakushoku_list[] =$value;
		}
		$this->bu_list       = $bu_list;
		$this->ka_list       = $ka_list;
		$this->kakari_list   = $kakari_list;
		$this->yakushoku_list= $yakushoku_list;

	}
}

★これで、なんで戻るボタンはアンカータグなのか
なぜjsは return false;なのか分かった!!

https://blog.goo.ne.jp/xmldtp/e/0884dbe92721ab84cb27d212ca631094


classees/validation.php

<?php
class Extension
{
	const BUCHOU = 4;
	const KACHOU = 3;
	const KK     = 2;
	const HIRA   = 1;
	static $ja_to_num = array(
		'buchou' => self::BUCHOU,
		'kachou' => self::KACHOU,
		'KK'     => self::KK,
		'hira'   => self::HIRA,
	);
	static $each_to_affi = array(
		//1課
		'2' => array('3','4','5'),
		//2課
		'6' => array('7','8','9'),
		//3課
		'10' => array('11','12','13'),
	);

	/*
	 * 役職と所属が対応しているか
	 */
    public static function _validation_correct_yakushoku()
    {
    	$bu          			 = Input::post('bu', null);
    	$ka                      = Input::post('ka', null);
    	$kakari                  = Input::post('kakari', null);
    	$yakushoku               = Input::post('yakushoku', null);

    	//役職名(日本語)を役職(id)②変換
    	if (array_key_exists($yakushoku, self::$ja_to_num)){
    		$yakushoku_num  =  self::$ja_to_num[$yakushoku];
    	}
    	//部所属の場合、部長のみOK
    	if(empty($ka)){
    		$result =  ($yakushoku_num == self::BUCHOU) ? true: false;
    		return $result;
    	}
    	//課所属の場合、課長のみOK
    	else if(empty($kakari)){
    		$result =  ($yakushoku_num == self::KACHOU) ? true: false;
    		return $result;
    	}
    	else{
    	//係所属の場合、係長と一般OK
    		if ($yakushoku_num == self::KK or $yakushoku_num == self::HIRA){
				return true;
    		}
    		else{
    			return false;
    		}
    	}
    }

    /*
     * 部長は部に1人だけ
     */
    public static function _validation_only_one_yakushoku()
    {
    	$bu          			 = Input::post('bu', null);
    	$ka                      = Input::post('ka', null);
    	$kakari                  = Input::post('kakari', null);
    	$yakushoku               = Input::post('yakushoku', null);

    	//役職名(日本語)を役職(id)に変換
    	if (array_key_exists($yakushoku, self::$ja_to_num)){
    		$yakushoku_num  =  self::$ja_to_num[$yakushoku];
    	}
    	var_dump($yakushoku_num);
    	//$affiliation = self::$each_to_affi[$bu];
		//各々の所属から所属番号(通しid)への変換
    	$affiliation=  $ka     ? self::$each_to_affi[$bu][$ka] : self::$each_to_affi[$bu];
    	$affiliation = $kakari ? self::$each_to_affi[$bu][$ka][$kakari] : self::$each_to_affi[$bu][$ka];
    	var_dump($affiliation);

//     	$already_exists_row = get_count_column($affiliation, $yakushoku_num);
//     	if(!empty ($already_exists_row)){
// 			return false;
// 		}else {
// 			return true;
// 		}
    }
}

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 %}

 

0419

http://piyopiyocs.blog115.fc2.com/blog-entry-596.html
http://fuelphp.jp/docs/1.7/packages/orm/crud.html
http://fuelphp.jp/docs/1.7/classes/pagination.html
http://fuelphp.jp/docs/1.7/classes/database/usage.html

[ ] js changeイベントが走らない
→DOM読み込みしてないから https://blog.falconsrv.net/articles/512
★DOMとは、$(document)readyとはhttps://qiita.com/8845musign/items/88a8c693c84ba63cea1d

たぶんこれが一覧の検索条件系の答えw
http://phpjavascriptroom.com/?t=js&p=location4

jqueryでセルフ定義関数を呼び出すときの括弧

特に機能を持たない汎用ボタン(formの指定urlではなくて、jsで遷移)の作り方
http://www.htmq.com/html5/input_type_button.shtml

onclickでjquery側のセルフ定義関数を呼んでもnot defined https://altarf.net/computer/javascript-jquery-computer/1534
→ ★即時関数
http://web-wizardry.net/jquery/jquery%E3%81%AE%E8%AA%AD%E8%BE%BC%E3%81%BFready%E3%81%A8load%E3%81%AE%E9%A0%86%E7%95%AA%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6/
headに書くのが最速? n

<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> </head> {% block content %}<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>{{ random() }}{% endblock %}

 

 

 

 

 

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<detail.js>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

 

 

$(function (){ $(function (){ $(".iddiv").click(function(){ var thisrow = $(this).parent(); var thisrowid = $(thisrow).attr("id"); console.log(thisrowid); $(function(){ $.ajax({ url:'http://localhost/fuelphp-1.7.3/public/index.php/detail/detail.json', type:'POST', dataType:"JSON", data: { "employee_id": thisrowid }, success:function(data){ var jsondata = JSON.parse(data) console.log(jsondata); console.log(jsondata['id']);                     },                     error:function(data){ //DOM操作がわかんないや console.log('エラーっすわ');                     }

                })             }); }); });

 

 

 

<<<<<<<<>>>>>れすとこん>>>>>>>>>>>>>>>>>

<?php<?phpclass 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); }}

 

0417 一覧表示とjsで詳細表示

- 部署情報(affilation)を正しく結合して、ひとつのテーブル要素として表示
  ★implode 配列要素を文字列として結合
  ★存在するなら~ 3項演算子
- 選択したカラムのみを取得
   http://fuelphp.jp/docs/1.6/packages/orm/crud.html#partial_selects
-RESTConからajaxで取得したデータを変換
  ★JSONにはObj型と配列型がある
   phpやjsで用いるには、各々の変数としてデコードする必要がある
jsではJSON.parse(JSON変数);
   http://www.task-notes.com/entry/20160719/1468858991
   https://teratail.com/questions/19313

----------------------------------------------------------------------------------------------------------------------

Fuel\Core\Database_Exception [ 1054 ]:
SQLSTATE[42S22]: Column not found: 1054
Unknown column 't2.sorting ' in 'field list' with query:
"SELECT `t0`.`id` AS `t0_c0`,
`t0`.`family_name` AS `t0_c1`,
`t0`.`given_name` AS `t0_c2`,
`t0`.`phonetic_of_family_name` AS `t0_c3`,
`t0`.`phonetic_of_given_name` AS `t0_c4`,
`t0`.`affiliation_id` AS `t0_c5`,
`t0`.`position_id` AS `t0_c6`,
`t0`.`picture_url` AS `t0_c7`,
`t0`.`comments` AS `t0_c8`,
`t0`.`has_been_deleted` AS `t0_c9`,
`t0`.`number_of_editing` AS `t0_c10`,

`t1`.`department_name` AS `t1_c0`,
`t1`.`section_name` AS `t1_c1`,
`t1`.`subsection_name` AS `t1_c2`,
`t1`.`sorting` AS `t1_c3`,
`t1`.`id` AS `t1_c4`,

`t2`.`assigned_name` AS `t2_c0`,
`t2`.`sorting ` AS `t2_c1`,
`t2`.`id` AS `t2_c2`


FROM `employee` AS `t0`
LEFT JOIN `affiliation` AS `t1` ON (`t0`.`affiliation_id` = `t1`.`id`)
LEFT JOIN `position` AS `t2` ON (`t0`.`position_id` = `t2`.`id`)"

//ORMの本質はLEFTJOINじゃん