[CakePHP3.10] 検索

<p>This is People table records.</p>
<?=$this->Form->create(null, ["type"=>"post", "url"=>["controller"=>"People", "action"=>"index"]]) ?>
<div>find</div>
<div><?=$this->Form->text("People.find") ?></div>
<div><?=$this->Form->submit("検索") ?></div>
<?=$this->Form->end() ?>

Controller

	public function index(){
		if($this->request->is('post')){
			$find = $this->request->data['People']['find'];
			$condition = ['conditions'=>["name"=>$find]];
			$data = $this->People->find("all", $condition);
		} else {
			$data = $this->People->find("all");
		}
		$this->set('data', $data);
	}

### 曖昧検索

	public function index(){
		if($this->request->is('post')){
			$find = $this->request->data['People']['find'];
			$condition = ['conditions'=>["name like"=>$find]];
			$data = $this->People->find("all", $condition);
		} else {
			$data = $this->People->find("all");
		}
		$this->set('data', $data);
	}

決まった年齢以下の人だけ検索
$condition = [“conditions” => [“age <=" => $find]];

	public function index(){
		if($this->request->is('post')){
			$find = $this->request->data['People']['find'];
			$arr = explode(",", $find);
			$condition = ['conditions'=>[
				"and"=> [
					"age >=" => $arr[0],
					"age <=" => $arr[1]
				]
			]];
			$data = $this->People->find("all", $condition);
		} else {
			$data = $this->People->find("all");
		}
		$this->set('data', $data);
	}

### 並び順

	public function index(){
		if($this->request->is('post')){
			$find = $this->request->data['People']['find'];
			$condition = [
				'conditions'=>["name like" => $find],
				"order" => ["People.age" => "desc"]
			];
			$data = $this->People->find("all", $condition);
		} else {
			$data = $this->People->find("all");
		}
		$this->set('data', $data);
	}

### 必要な部分だけ取り出す
– 取り出す位置の設定「offset」
– 取り出すレコード数の設定「limit」
– 取り出すページの設定「page」

	public function index(){
		if($this->request->is('post')){
			$find = $this->request->data['People']['find'];
			$condition = [
				'limit'=> 3,
				"page" => $find
			];
			$data = $this->People->find("all", $condition);
		} else {
			$data = $this->People->find("all", ["order"=> ["People.age" => "asc"]]);
		}
		$this->set('data', $data);
	}