我一直在使用cakePHP pagination选项2天.我需要一个INNER加入列出几个字段,但我必须处理搜索过滤结果.
这是我通过$this-> passedArgs处理搜索选项的代码的一部分
这是我通过$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->分页忽略每个$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.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 [‘条件] [] [‘Member.cognome LIKE’],你可以看到
array $this-> passedArgs
Array ( [Search.cognome] => aiello ) Array $this->paginate['conditions'][] ( [0] => Array ( [Member.cognome LIKE] => aiello ) [1] => Array ( [Member.sospeso] => NO )
但是,如果我使用分页写入联接,那么$this-> paginate [‘conditions’] []将忽略所有的东西,并让我从调试开始,只需$this-> paginate [‘conditions’] [] [ ‘Reservation.pagamento_verificato’] =’SI’;
另一点信息.
如果我把所有处理$this-> paginate [‘conditions’] [] [‘Reservation.pagamento_verificato’] =’SI’的东西;
在$this-> paginate JOIN之前,在$this-> paginate [‘conditions’] []中不会有任何内容.
这是一个古老的问题,所以我只想回顾一下如何在分页中为从Google那里来的人分一个JOIN.以下是Widget控制器的示例代码,将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','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}
还有分页.