0

Cakephp検索プラグインを使用しようとしていますが、queryメソッドを使用して結果をフィルタリングする際に問題が発生します。$ filterArgs配列で宣言されているfindByLength()という関数を作成しました。構築しているアレイが正しいかどうかはわかりません。SQLステートメントを見ると、呼び出されていないように見えます。何か案は?ありがとう!

<?php
// findByLength() is not affecting the sql like expected. Any ideas?
// using http://cakedc.com/downloads/view/cakephp_search_plugin

    public $filterArgs = array(
            array('name' => 'name', 'type' => 'like'),
            array('name' => 'search', 'type' => 'like', 'field' => 'Trail.description'),
            array('name' => 'type','type'=>'string'),
            array('name'=>'dogs_allowed','type'=>'value'),
            array('name'=>'area_id','type'=>'value'),
            array('name' => 'length', 'type' => 'query', 'method' => 'findByLength', 'field' => 'Trail.length'),
            array('name' => 'state_id','field'=>'Area.state_id', 'type' => 'value'),
            array('name'=>'created_by_pt','field'=>'Trail.created_by','type'=> 'value'),
            //array('name'=>'created_by_user','field'=>'Trail.created_by','type'=> 'value'),
 );
    public function findByLength(){

        if(empty($data['Trail']['length'])){
            return array();
        }
        switch($data['Trail']['length']){
            case 0:
                return array('AND'=> array($this->alias.'.length >='=> $data['Trail']['length'],
                                                                     $this->alias.'.length <'=> $data['Trail']['length'] + 3)

                                );
            break;
            case 3:
                return array('AND'=> array($this->alias.'.length >='=> $data['Trail']['length'],
                                                                     $this->alias.'.length >'=> $data['Trail']['length'] + 3)

                                );
            break;
            case 6:
            return array('AND'=> array($this->alias.'.length >='=> $data['Trail']['length'],
                                                                 $this->alias.'.length <'=> $data['Trail']['length'] + 4)

                            );
            break;
            case 10:
            return array('AND'=> array($this->alias.'.length >='=> $data['Trail']['length'])

                            );
            break;
        }

    }

?>
4

1 に答える 1

1

間違った配列キーを参照していたことがわかりました。

$data['Trail']['length'] ended up being $data['length']

と変更されました

public function findByLength(){

public function findByLength($data = array()){
于 2011-07-27T16:18:12.773 に答える