2012-04-26 19 views
0

私は2つのテーブルを持っています結果を(cakephp search pluginを使用して)従業員のユーザ名で検索する必要がありますが、evaluation_resultsテーブルではユーザ名ではなく従業員のID(evaluation_employee_id)を持っています。私は、それらのテーブルをリンクさせて動作させる方法を知らない。CakePHPの別のテーブルのフィールドで検索

私のビューにコード(evaluation_results/index.ctp):

echo $this->Form->create('EvaluationResult', array(
      'url' => array_merge(array('action' => 'index'), $this->params['pass']) 
      )); 
echo $this->Form->input('username', array('div' => false, 'empty' => true)) . '<br/><br/>'; 
echo $this->Form->submit(__('Search', true), array('div' => false)); 
echo $this->Form->end(); 

コードするコントローラで(evaluation_results_controller.php):

var $components = array('Search.Prg'); 
    function index() { 
     $this->Prg->commonProcess(); 
     $this->EvaluationResult->recursive = 0; 
     $this->paginate = array(
        'conditions' => $this->EvaluationResult->parseCriteria($this->passedArgs)); 
     $this->set('evaluationResults', $this->paginate()); 
    } 

コード私のモデルで(evaluation_result.php):

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

    //Search fields data description for processing. 
    public $filterArgs = array(
     array('name' => 'EvaluationEmployee.username', 'type' => 'query', 'method' => 'filterUsername') 
    ); 

    //Method as decalred in $filterArgs to process the free form search. 
    public function filterUsername($data, $field = null) { 
     if (empty($data['EvaluationEmployee']['username'])) { 
      return array(); 
     } 
     $username = '%' . $data['EvaluationEmployee']['username'] . '%'; 
     return array(
       $this->alias . '.EvaluationEmployee.username LIKE' => $username 
      ); 
    } 

詳細情報が必要な場合は教えてください。

答えて

関連する問題