CakePHP LEFT JOIN 排序问题
CakePHP LEFT JOIN sorting issue
我正在使用 cakePhp 2.x 版本,下面是我的数据网格视图和控制器,我希望区域和框都按用户排序。 Box 可以排序,但是Area first sorting 是有效的,点击排序之后,页面刷新了但是没有排序。可能是什么原因?
<table class="index">
<thead>
<tr>
<th><?php echo $this->Paginator->sort('A.title', 'Area')?></th>
<th><?php echo $this->Paginator->sort('B.title', 'Boxes')?></th>
<th>Internal</th>
<th>External</th>
</tr>
</thead>
$this->paginate['contain'] = array();
$this->paginate['joins'] = array(
array(
'table' => 'a_table',
'alias' => 'A',
'type' => 'LEFT',
'conditions' => array(
'A.key = B.id',
'A.status' => 'Active'
)
)
);
$conditions = array();
$this->paginate['fields'] = array('B.*', 'A.title');
$this->paginate['order'] = array('A.title', 'B.title');
if(!empty($this->request->data['SignalBox']))
{
if($this->request->data['SignalBox']['box'])
$conditions['B.title LIKE'] = '%'.$this->request->data['SignalBox']['box'].'%';
if($this->request->data['SignalBox']['area'])
$conditions['A.title'] = $this->request->data['SignalBox']['area'];
}
if($conditions)
$this->paginate['conditions'] = $conditions;
$data = $this->paginate('B');
$this->set('data', $data);
最终解决方案是,更改模型
根据提交的排序列,
$model ='A';
if($this->request->param('named.sort')){
$submittedModel = explode('.',$this->request->param('named.sort'));
$model =$submittedModel [0];
}
然后更改 JOIN 查询并
$data = $this->paginate('B');
if(A)
{
A JOIN query
}
else
{
B JOIN query
}
我正在使用 cakePhp 2.x 版本,下面是我的数据网格视图和控制器,我希望区域和框都按用户排序。 Box 可以排序,但是Area first sorting 是有效的,点击排序之后,页面刷新了但是没有排序。可能是什么原因?
<table class="index">
<thead>
<tr>
<th><?php echo $this->Paginator->sort('A.title', 'Area')?></th>
<th><?php echo $this->Paginator->sort('B.title', 'Boxes')?></th>
<th>Internal</th>
<th>External</th>
</tr>
</thead>
$this->paginate['contain'] = array();
$this->paginate['joins'] = array(
array(
'table' => 'a_table',
'alias' => 'A',
'type' => 'LEFT',
'conditions' => array(
'A.key = B.id',
'A.status' => 'Active'
)
)
);
$conditions = array();
$this->paginate['fields'] = array('B.*', 'A.title');
$this->paginate['order'] = array('A.title', 'B.title');
if(!empty($this->request->data['SignalBox']))
{
if($this->request->data['SignalBox']['box'])
$conditions['B.title LIKE'] = '%'.$this->request->data['SignalBox']['box'].'%';
if($this->request->data['SignalBox']['area'])
$conditions['A.title'] = $this->request->data['SignalBox']['area'];
}
if($conditions)
$this->paginate['conditions'] = $conditions;
$data = $this->paginate('B');
$this->set('data', $data);
最终解决方案是,更改模型 根据提交的排序列,
$model ='A';
if($this->request->param('named.sort')){
$submittedModel = explode('.',$this->request->param('named.sort'));
$model =$submittedModel [0];
}
然后更改 JOIN 查询并
$data = $this->paginate('B');
if(A)
{
A JOIN query
}
else
{
B JOIN query
}