我有两张桌子:
- evaluation_employees 字段:id、用户名
- 评估结果字段:id、等级、评估员工 ID
在评估结果视图中,我需要通过员工的用户名搜索结果(使用cakephp 搜索插件),但在评估结果表中,我有员工的 id(evaluation_employee_id),而不是用户名。我不知道如何在这些表之间建立链接以使其正常工作。
我认为的代码(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
);
}
请告诉我是否需要更多信息。