我开发了一个蛋糕 php 应用程序。
在这有学生,展示位置,批次,公司等表
在展示位置表中有 student_id、company_id,在学生表中有 batch_id 列。
在展示位置索引页面中,我应用了 jq 网格。这是屏幕截图。
我想搜索学生、公司和批次。为此,我在放置控制器索引函数中使用了可包含的行为。
if( $this->params['url']['_search'] == 'true' ) /* For Searching*/
{
//pr($this->params);
$searchconditions = array();
if( isset($this->params['url']['studentname']) && !empty($this->params['url']['studentname']) )
{
array_push(&$searchconditions, array('Student.fullname LIKE' => $this->params['url']['studentname'] . '%'));
}
if( isset($this->params['url']['companyname']) && !empty($this->params['url']['companyname']) )
{
array_push(&$searchconditions, array('Company.name LIKE' => $this->params['url']['companyname'] . '%'));
}
if( isset($this->params['url']['batchname']) && !empty($this->params['url']['batchname']) )
{
array_push(&$searchconditions, array('Batch.name LIKE' => $this->params['url']['batchname'] . '%'));
}
$result = $this->Placement->find('all', array(
'fields' => array('id','student_id','company_id'),
'contain' => array(
'Student' => array(
'fields' => array('id','fullname','batch_id'),
'Batch' => array(
'fields'=> array('id','name')
)
),
'Company' => array(
'fields' => array('id','name')
)
),
'conditions' => $searchconditions,
'order' => $sort_range,
'limit' => $limit_range
));
}
else /* Default display*/
{
$result = $this->Placement->find('all', array(
'fields' => array('id','student_id','company_id'),
'contain' => array(
'Student' => array(
'fields' => array('id','fullname','batch_id'),
'Batch' => array(
'fields'=> array('id','name')
)
),
'Company' => array(
'fields' => array('id','name')
)
),
'order' => $sort_range,
'limit' => $limit_range
));
}
网格中填充了学生姓名、公司名称和批次名称(如果有)。如果我按学生姓名和公司名称搜索,搜索也可以正常工作,但是当我尝试按批次名称搜索时,出现以下错误:
Warning (512): SQL Error: 1054: Unknown column 'Batch.name' in 'where clause' [APP\vendors\cakephp\cake\libs\model\datasources\dbo_source.php, line 681]
Query: SELECT `Placement`.`id`, `Placement`.`student_id`, `Placement`.`company_id`, `Student`.`id`, `Student`.`fullname`, `Student`.`batch_id`, `Company`.`id`, `Company`.`name` FROM `placements` AS `Placement` LEFT JOIN `students` AS `Student` ON (`Placement`.`student_id` = `Student`.`id`) LEFT JOIN `companies` AS `Company` ON (`Placement`.`company_id` = `Company`.`id`) WHERE `Batch`.`name` LIKE 'df%' ORDER BY `Placement`.`id` asc LIMIT 0,10
我认为从查询中可以看出学生和批次之间的关系不起作用。
我无法弄清楚它为什么会这样。
请帮助我。
谢谢