0

フォームの条件検索を使用して、CakePHP2.xにページ付けを追加しようとしています。ただし、ビューでは、次のページに私の状態が表示されません。これが私のコードです:

コントローラ

public function result($palabraclave = null)
    {
      $this->layout = 'tempart';
          $this->paginate = array(
            'limit' => 5,
            'order' => array(
                'Articulo.created' => 'desc'),
                'conditions'=>array("titulo like ?"=>"%".$this->data['Paginas']['palabraclave']."%") 
        )
       $data = $this->paginate('Articulo');//Consulta a la base de datos
        $this->set(compact('data'));
    }

「次へ」をクリックして検索の次のページの結果を表示すると、1ページから2ページへのページネーション条件が渡されません。:(

意見:

    <div style="display: inline-block;  width:70%;" id="test">
<?php foreach ($data as $da): ?>

<br />

<article>   
<?php echo $this->Html->image('article_preview/mini_'.$da['Articulo']['imagen'], array('alt' => 'Hospital-Excel'))?>
<div style="text-align:left;">
<?php echo $this->Html->link("<h6 class='artnombre'>".$da['Articulo']['titulo']."<h6>", array('class'=>"artnombre",'action'=> 'articulo',$da['Articulo']['id']),array('escape' => false)); ?> 

</div>
<br />
<p> 
<?php echo $da['Articulo']['descripcion']; ?>               <?php echo $this->Html->link('Read more ....', array('action'=> 'articulo',$da['Articulo']['id'])); ?>  
<h5></h5>
</p>
<div class="puntoshorizontal" style="clear"></div>
</article>  
<?php endforeach; ?>



<div style="text-align:center">
<?php
// Shows the page numbers
// Shows the next and previous links
echo $this->Paginator->prev('« Back', null, null, array('class' => 'disabled')) . " |";
echo $this->Paginator->numbers(). "| "; 
echo $this->Paginator->next('Next »', null, null, array('class' => 'disabled'));
echo "<br />";
echo $this->Paginator->counter();
// prints X of Y, where X is current page and Y is number of pages


?>
</div>

</div>
4

3 に答える 3

1

各ページで検索パラメータを保持する方法は、次のようにする必要があります。データを投稿した後、メソッドに$ this-> data ['Paginas'] ['palabraClave']があり、セッションに保存します。したがって、その後の/ resultados / pag1,2、.. nの呼び出しごとに、セッションからパラブラクレーブの値を取得します。

最後に、次のようなものが得られます。

public function resultados(){
    $conditions = array();

    if($this->Session->check('conditions')){
      $conditions = $this->Session->read('conditions');
    }

    if(isset($this->data)){
        $conditions = array("titulo LIKE" => "%".this->data['Paginas']'palabraclave']"%",));
    //save to the session
    $this->Session->write('conditions',$conditions);
    }
    $data = $this->painate('Articulo',$conditions);
    $this->set('data');
}

これには多少の調整が必要かもしれませんが、私が思う考えは明らかです。

于 2013-06-06T15:51:45.133 に答える
0

次のように、paginateメソッドを呼び出すときにpaginate条件を設定します。

$data = $this->paginate('Articulo', array(
    "titulo LIKE" => "%" . $this->data['Paginas']['palabraclave'] . "%",
));

paginateプロパティとは対照的に。

于 2012-10-04T00:03:53.553 に答える
0

これは例です:

1:すべてのURL引数をページネーター関数に渡します

$this->Paginator->options(array('url' => $this->passedArgs));

2:よくある間違い:paginateで条件検索を続けない

if($this->data){
    $this->passedArgs = array(
       'name' => $this->data[‘User’]['name']
    );
}else{
    if(isset($this->passedArgs['name'])){
         $this->data[‘User’]['name'] = $this->passedArgs['name'];
    }else{
         $this->data[‘User’]['name'] = ;
    }
}
于 2014-07-01T09:16:32.797 に答える