Cakephp-按不同表的字段搜索

Cakephp-按不同表的字段搜索,php,cakephp,search,cakephp-1.3,Php,Cakephp,Search,Cakephp 1.3,我有两张桌子: 员工评价 字段:id、用户名 评价结果 字段:id、等级、评估\员工\ id 在“评估结果”视图中,我需要按员工的用户名搜索结果(使用),但在“评估结果”表中,我有员工id(评估员工id),而不是用户名。我不知道如何在这些表之间建立链接,使其工作 我眼中的代码(evaluation\u results/index.ctp): 我的模型中的代码(evaluation_result.php): 如果需要更多信息,请告诉我。如果您在模型中设置了关联,则在搜索员工时,它将自动查找所有相关

我有两张桌子:

  • 员工评价 字段:id、用户名
  • 评价结果 字段:id、等级、评估\员工\ id
  • 在“评估结果”视图中,我需要按员工的用户名搜索结果(使用),但在“评估结果”表中,我有员工id(评估员工id),而不是用户名。我不知道如何在这些表之间建立链接,使其工作

    我眼中的代码(evaluation\u results/index.ctp):

    我的模型中的代码(evaluation_result.php):


    如果需要更多信息,请告诉我。

    如果您在模型中设置了关联,则在搜索员工时,它将自动查找所有相关记录

    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();
    
    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());
        }
    
    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
                );
        }