プログラミング奮闘記録

プラグラマーへ奮闘。PHP・Cakephp・JavaScript・isoアプリのコード勉強ブログです。その他の言語やツールなども使用します。

cakephp 整理します。キーワード検索

検索を前にいろいろ試したり、実装してましたが自分でまとめてたはずが、

まとまっておらず。。ww

 

再度まとめ。ww

 

キーワード検索(一部一致)

 

>>>index.ctp

<!--検索フォーム(一部一致)-->
<?php echo $this->Form->create('post', array('action'=>'find')); ?>
<fieldset>
<legend>検索</legend>
<?php echo $this->Form->input('title', array('label' => 'タイトル', 'class' => 'span12', 'placeholder' => 'タイトルを検索')); ?>
</fieldset>
<?php echo $this->Form->end('検索'); ?>

 

 

>>>Model.php

public $actsAs = array('Search.Searchable');
public $filterArgs = array(
// 例
'title' => array('type' => 'like'),
'comment' => array('type' => 'like'),
);

 

 

>>>Controller.php

public $components = array('Search.Prg');
public $presetVars = true;

 

public function find(){
$this->Post->recursive = 0;
$this->Prg->commonProcess();
$this->paginate = array(
'conditions' => $this->Post->parseCriteria($this->passedArgs),
);
$this->set('posts', $this->paginate());
}

 

 

 

これで実装可能。