0

https://github.com/cakedc/searchで検索プラグインを使用しています。ID フィールドのみを使用してレコードを検索しようとしています。つまり、フォーム入力に 1 と入力すると、ユーザー ID 1 のレコードが表示される必要があります。 id フィールド、検索機能の入力フィールドがインデックス ビューに表示されなくなります。奇妙なことに、入力フィールドに表示される別のフィールド名を指定すると、

以下は私のモデルの私のコードです

public $actsAs = array('Search.Searchable');

public $filterArgs = array(
'id' => array('type' => 'like', 'field' => 'ItSupportRequest.id'),
);

public function findByTags($data = array()) {
$this->Tagged->Behaviors->attach('Containable', array('autoFields' => false));
$this->Tagged->Behaviors->attach('Search.Searchable');
$query = $this->Tagged->getQuery('all', array(
'conditions' => array('Tag.name'  => $data['tags']),
'fields' => array('foreign_key'),
'contain' => array('Tag')
));
return $query;
}

public function orConditions($data = array()) {
$filter = $data['filter'];
$cond = array(
'OR' => array(
$this->alias . '.id LIKE' => '%' . $filter . '%',
));
return $cond;

}

ここに私のコントローラーコードがあります。

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

public $presetVars = true; // using the model configuration

public function find() {
$this->Prg->commonProcess();
$this->paginate['conditions'] = $this->ItSupportRequest->parseCriteria($this->passedArgs);
$this->set('articles', $this->paginate());
}

私のindex.ctpファイルには、このコードがあります。

<?php 
echo $this->Form->create('ItSupportRequest', array(
'url' => array_merge(array('action' => 'find'), $this->params['pass'])
));
echo $this->Form->label('Query ID:') . "<br/>";        
echo $this->Form->input('name', array('div' => false, 'label' => false));

echo $this->Form->submit(__('Search'), array('div' => false));
echo $this->Form->end();
?>  

前もって感謝します。

4

1 に答える 1

0

id は非表示になるため、id と呼ぶべきではありません (cake はこれを主キーと想定しているため)。

別の名前を付けるか、この動作を手動で上書きします

$this->Form->input('id', array('type' => 'text'));

しかし、私は「検索」のように sth を使用し、

$this->Form->input('search', array('placeholder' => 'ID to look for'));

public $filterArgs = array(
    'search' => array('type' => 'like', 'field' => 'ItSupportRequest.id'),
);
于 2013-02-18T12:45:45.390 に答える