gpt4 book ai didi

Cakephp $ this->使用自定义JOIN和过滤选项进行分页

转载 作者:行者123 更新时间:2023-12-04 03:05:30 24 4
gpt4 key购买 nike

我已经使用了Cakephp分页选项2天了。我需要进行“内部联接”以列出一些字段,但是我必须处理搜索以过滤结果。
这是代码的一部分,其中我通过$this->passedArgs处理搜索选项

function crediti() {

if(isset($this->passedArgs['Search.cognome'])) {
debug($this->passedArgs);

$this->paginate['conditions'][]['Member.cognome LIKE'] = str_replace('*','%',$this->passedArgs['Search.cognome']);

}
if(isset($this->passedArgs['Search.nome'])) {
$this->paginate['conditions'][]['Member.nome LIKE'] = str_replace('*','%',$this->passedArgs['Search.nome']);

}

之后
$this->paginate = array(

'joins' => array(array('table'=> 'reservations',
'type' => 'INNER',
'alias' => 'Reservation',
'conditions' => array('Reservation.member_id = Member.id','Member.totcrediti > 0' ))),
'limit' => 10);
$this->Member->recursive = -1;
$this->paginate['conditions'][]['Reservation.pagamento_verificato'] = 'SI';
$this->paginate['fields'] = array('DISTINCT Member.id','Member.nome','Member.cognome','Member.totcrediti');
$members = $this->paginate('Member');
$this->set(compact('members'));

INNER JOIN的效果很好,但是$ this-> paginations忽略了每个 $this->paginate['conditions'][] by $this->passedArgs,我不知道该如何解决。
在调试中没有查询,只有原始的 INNER JOIN
有人可以帮我吗?
非常感谢你

更新:
没有运气。
我已经处理了这部分代码很多小时了。
如果我用
if(isset($this->passedArgs['Search.cognome'])) {
$this->paginate['conditions'][]['Member.cognome LIKE'] = str_replace('*','%',$this->passedArgs['Search.cognome']);

}
$this->paginate['conditions'][]['Member.sospeso'] = 'SI';
$this->Member->recursive = 0;
$this->paginate['fields'] = array(
'Member.id','Member.nome','Member.cognome','Member.codice_fiscale','Member.sesso','Member.region_id',
'Member.district_id','Member.city_id','Member.date','Member.sospeso','Region.name','District.name','City.name');
$sospesi = $this->paginate('Member');

一切顺利,从调试中我收到了第一个条件,以及 $this->paginate['conditions'][]['Member.cognome LIKE']的条件,如您所见
数组 $this->passedArgs
Array
(
[Search.cognome] => aiello
)

Array $this->paginate['conditions'][]
(
[0] => Array
(
[Member.cognome LIKE] => aiello
)

[1] => Array
(
[Member.sospeso] => NO
)

但是,如果我用paginate编写联接, $this->paginate['conditions'][]将忽略所有内容,并从调试中给我,只是 $this->paginate['conditions'][]['Reservation.pagamento_verificato'] = 'SI';另一点信息。
如果我把所有与 $this->paginate['conditions'][]['Reservation.pagamento_verificato'] = 'SI';有关的东西放进去
$this->paginate JOIN之前, $this->paginate['conditions'][]中将没有任何内容。

最佳答案

这是一个古老的问题,因此,我将回顾一下如何像我一样从谷歌到这里的其他人分页进行JOIN。这是来自窗口小部件 Controller 的示例代码,将Widget.user_id FK连接到User.id列,仅显示当前用户(在条件下):

// Limit widgets shown to only those owned by the user.
$this->paginate = array(
'conditions' => array('User.id' => $this->Auth->user('id')),
'joins' => array(
array(
'alias' => 'User',
'table' => 'users',
'type' => 'INNER',
'conditions' => '`User`.`id` = `Widget`.`user_id`'
)
),
'limit' => 20,
'order' => array(
'created' => 'desc'
)
);
$this->set( 'widgets', $this->paginate( $this->Widget ) );

这使得查询类似于:
SELECT widgets.* FROM widgets 
INNER JOIN users ON widgets.user_id = users.id
WHERE users.id = {current user id}

并且仍然分页。

关于Cakephp $ this->使用自定义JOIN和过滤选项进行分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5728932/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com