質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

Q&A

解決済

1回答

1887閲覧

cakephp でSearchプラグインでキーワードと複数のチェックボックなど色々な検索をしたいです。

akobayashi

総合スコア15

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

0グッド

0クリップ

投稿2017/11/21 08:56

編集2017/11/22 07:02

現在cakephp 2.x(もうちょっとで3に以降予定です)
で、検索機能を作っていますが、Search プラグインを使っておりますが、
ハマってしまいうまくできません。サイトもぐぐってみましたが、
イマイチやりたいことと合わず駆け込み的にこちらで質問させていただきます。
※やりたいこと
複数のチェックボックスや、キーワードを組み合わせて絞込検索を作りたいです。

例:https://hoiku-shigoto.com/
このサイトの「こだわり条件から探す」みたいなシステムにしたいです。

ちなみに、うまく行かなかったコードが以下です。

モデル
class User extends AppModel{
public $belongsTo = array('Region','Sregion','Money','Shokushu','Koyou');
public $actsAs = array('Search.Searchable');
public $filterArgs = array(
'keyword' => array('type' => 'like','field' => array('User.title','User.username','User.email','User.comment'), 'connectorAnd' => ' ', 'connectorOr' => ''),
'caram_id' => array('type' => 'subquery','method' => 'searchIn','field' => array('User.region_id','User.sregion_id','User.money_id','User.shokushu_id','User.koyou_id')),

);

コントローラー

class UsersController extends AppController {
public $components = array('Search.Prg');
public $presetVars = true;

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

}

カテゴリーをつけるために$belongsToで紐付けています。
これらのカテゴリーをviewではチェックボックスみたいに表示させて、
キーワードも含ませて検索したいです。

もしかしたらSearchプラグインを使わないほうがやりやすいのかも?と今思っております・
何卒よろしくお願いいたします・

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

モデル

<?php App::uses('AppModel','Model'); class Bottom extends AppModel{ public $belongsTo = array('Region','Sregion','Money','Shokushu','Koyou'); public $order = array('Bottom.id DESC'); public $actsAs = array('Search.Searchable'); public $filterArgs = array( 'keyword' => array('type' => 'like','field' => array('Bottom.title','Bottom.comment','Bottom.username','Bottom.email'), 'connectorAnd' => '+', 'connectorOr' => ','), 'koyou_id' => array('type' => 'value','field' => array('Bottom.koyou_id')), 'money_id' => array('type' => 'value','field' => array('Bottom.money_id')), 'region_id' => array('type' => 'value','field' => array('Bottom.region_id')), 'sregion_id' => array('type' => 'value','field' => array('Bottom.sregion_id')), 'shokushu_id' => array('type' => 'value','field' => array('Bottom.shokushu_id')), ); } コントローラ public function find() { $this->Bottom->recursive = 0; $this->Prg->commonProcess(); $this->paginate = array( 'conditions' => $this->Bottom->parseCriteria($this->passedArgs), ); $this->set('data', $this->paginate()); $this->set('list1',$this->Bottom->Koyou->find('list',array('fields'=>array('id','koyou_name')))); $this->set('list2',$this->Bottom->Money->find('list',array('fields'=>array('id','money_cate')))); $this->set('list3',$this->Bottom->Region->find('list',array('fields'=>array('id','region_name')))); $this->set('list4',$this->Bottom->Sregion->find('list',array('fields'=>array('id','sregion_name')))); $this->set('list5',$this->Bottom->Shokushu->find('list',array('fields'=>array('id','shokushu_name')))); } ヴュー <h1>検索機能</h1> <div class="row-fluid"> <div class="span9"> <?= $this->Form->create('Bottom');?> <?= $this->Form->input('keyword',array('type' => 'text','label' => 'キーワード検索'));?> <?= $this->Form->input('koyou_id',array('type' => 'select','options' => $list1,'empty' => true,'label' => '雇用形態'));?> <?= $this->Form->input('money_id',array('type' => 'select','options' => $list2,'empty' => true,'label' => '時給から'));?> <?= $this->Form->input('region_id',array('type' => 'select','options' => $list3,'empty' => true,'label' => '都道府県'));?> <?= $this->Form->input('sregion_id',array('type' => 'select','options' => $list4,'empty' => true,'label' => '小地区'));?> <?= $this->Form->input('shokushu_id',array('type' => 'select','options' => $list5,'empty' => true,'label' => '職種から'));?> <?= $this->Form->end('送信');?> <table> <?php if(isset($data)) :?> <?php foreach($data as $post):?> <tr><td><?= $this->Html->link('id',array('controller' => 'bottoms','action' => 'view',$post['Bottom']['id']));?></td></tr> <tr><td><?= $post['Bottom']['username'];?></td> <td><?= $post['Bottom']['title'];?></td> <td><?= $post['Bottom']['email'];?></td> <td><?= $post['Bottom']['comment'];?></td> <td><?= $post['Region']['region_name'];?></td> <td><?= $post['Sregion']['sregion_name'];?></td> <td><?= $post['Money']['money_cate'];?></td> <td><?= $post['Shokushu']['shokushu_name'];?></td> </tr> <?php endforeach;?> <?php endif;?> </table> </div>

投稿2017/11/22 10:11

akobayashi

総合スコア15

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問