0

私は次の検索フォームを持っています

<?php
echo $this->Form->create('Order', array('action' => 'search','type'=>'get'));?>
<?php echo $this->Form->input('SearchTerm',array('label' => 'Find:')); ?>
<?php $options=array('full_name'=>'By Name','code'=>'By Code','phone'=>'By Phone','email'=>'By Mail'); ?>
<?php echo $this->Form->input('options', array('type'=>'select', 'label'=>'Search:', 'options'=>$options)); ?>

<?php echo $this->Form->end('search'); ?>  

<?php if($rs!=0){?>
<?php if($rs!=null) { ?>
    results found : <?php print $results; //print_r ($result['Order']['full_name']); ?>
<h1 class="ico_mug">Results Matching Term: <?php print '"'.$term.'"' ;?></h1>
<table id="table">
    <tr>

        <th>Client Name</th>
        <th>Order Code</th>
        <th>Phone</th>
        <th>Received Order</th>
        <th>Working On Order </th>
        <th>Order Ready </th>
    </tr>

    <!-- Here is where we loop through our $posts array, printing out post info -->

    <?php foreach ($rs as $order): ?>
    <tr>

        <td>
            <?php echo $this->Html->link($order['Order']['full_name'],
            array('controller' => 'orders', 'action' => 'view', $order['Order']['id'])); ?>
        </td>
        <td><?php echo $order['Order']['code']; ?></td>
        <td><?php echo $order['Order']['phone']; ?></td>
        <td><?php echo $this->OrderStatus->getStatusString($order['Order']['receive_state']); ?></td>
        <td><?php echo $this->OrderStatus->getStatusString($order['Order']['working_state']); ?></td>
        <td><?php echo $this->OrderStatus->getStatusString($order['Order']['ready_state']); ?></td>
        <td> <?php //echo $this->Html->link($this->Html->image("cancel.jpg"), array('action' => 'index'), array('escape' => false));?><?php echo $this->Html->link($this->Html->image("edit.jpg"), array('action' => 'edit',$order['Order']['id']), array('escape' => false));/*echo $this->Html->link('Edit', array('action' => 'edit', $order['Order']['id']));*/?></td>
    </tr>
    <?php endforeach; ?>
    <tr ><?php //echo $this->Paginator->numbers(array('first' => 'First page')); ?></tr>
    <?php
    $urlParams = $this->params['url'];
    unset($urlParams['url']);
    $optionss=array('url' => array('?' => http_build_query($urlParams)));
    //$this->Paginator->options($optionss);
    $this->Paginator->settings['paramType'] = 'querystring';

    ?>

    <tr ><?php  //echo" << ".$this->Paginator->counter(
       // 'Page {:page} of {:pages}');
        ?></tr>

</table>

 <?php }else echo"no results found"; ?>


<?php } //endif?>

これが私のコントローラーアクションです

function search($options=null){
        $this->set('results',"");
        $this->set('term',"");
        $this->set('rs',0);    

        if ((isset($_GET["SearchTerm"]))||(isset($_GET["options"])) ) {
            $SearchTerm=$_GET["SearchTerm"];
            $options=$_GET["options"];

            if (!$options || !$SearchTerm) {
                $this->Session->setFlash('Please enter something to search for');
            }
            else {
                $SearchArray = array($options." LIKE " => "%".$SearchTerm."%");

                $this->paginate = array('conditions' =>  $SearchArray,'limit'=>2,'convertKeys' => array($options, $SearchTerm));
                $data=$this->paginate('Order');
                $this->set('rs', $data);
                $this->set('term',$SearchTerm);

            }
        }

ご覧のとおり、GetparametersオプションとSearchTermを使用しています。私はこれらの2人がページネーションリンクにとどまるようにしたい。私はstackoverflowや他のサイトで見つけたさまざまな修正を試しました(例:

$urlParams = $this->params['url'];
    unset($urlParams['url']);
    $optionss=array('url' => array('?' => http_build_query($urlParams)));

それでも私はまだ次のエラーメッセージを受け取ります:

オーバーロードされたプロパティPaginatorHelper::$ settingsの間接的な変更は、効果がありません[APP \ View \orders \ search.ctp、75行目

何故ですか?そしてこれに対する解決策はどうですか?(クックブックのwxampleを使用しても

$ this-> Paginator-> settings ['paramType']='クエリ文字列';

それでも同じエラーが発生します:S助けて/説明してもらえますか?

4

1 に答える 1

2

私があなたのコードを正しく理解していれば、あなたは次のものを置き換えることができるはずです:

<?php
    $urlParams = $this->params['url'];
    unset($urlParams['url']);
    $optionss=array('url' => array('?' => http_build_query($urlParams)));
    //$this->Paginator->options($optionss);
    $this->Paginator->settings['paramType'] = 'querystring';
?>

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

ページネーションのフォームフィールド 実際にフォーム要素をページネーションに入れようとしている場合は、コードを少し変更する必要があります。検索オプションの各項目に名前付きパラメーターを作成する必要があります。次に、コントローラーのアクションで、request->dataバージョンとparams['named']バージョンの両方の検索をチェックして、両方の場合にそれらを使用していることを確認する必要があります。また、コードをクリーンアップして、もう少し読みやすくします。

まず、データを取得するためにケーキメソッドを使用する必要があります。それはあなたなどのリクエストを確実にクリーンアップします。さらに、名前付き変数として渡され、フォームで送信される検索用語とフィルターオプションを考慮する必要があります。したがって、コントローラーを次のように更新する必要があります。

function search($options=null){

    $this->set('results',""); // where is this used ??
    $this->set('rs', 0); 
    $this->set('SearchTerm', '');
    $this->set('FilterBy', '');   
    $this->set('options', array('full_name'=>'By Name','code'=>'By Code','phone'=>'By Phone','email'=>'By Mail'));

    if ($SearchTerm = $this->request->data['Order']['SearchTerm']) or $SearchTerm = $this->params['named']['SearchTerm']) {
        if ($FilterBy = $this->request->data['Order']['FilterBy'] or $FilterBy = $this->params['named']['FilterBy'])) {
            $this->paginate = array(
                'conditions' => array($FilterBy." LIKE " => "%".$SearchTerm."%"), 
                'limit' => 2, 
                'convertKeys' => array($FilterBy, $SearchTerm)
            );
            $this->set('rs', $this->paginate('Order'));
            $this->set('SearchTerm', $SearchTerm);
            $this->set('FilterBy', $FilterBy);
        } else {
            $this->Session->setFlash('Please enter something to search for');
        }
    } else {
        $this->Session->setFlash('Please enter something to search for');
    }
}

次に、ビューに焦点を当てます。これを移動して削除します。

$options=array('full_name'=>'By Name','code'=>'By Code','phone'=>'By Phone','email'=>'By Mail');

ビューに表示されるべきではありません。これはコントローラーに属します(現在の場所です)。

次に、フォームをクリーンアップします。

<?php
  echo $this->Form->create('Order', array('action' => 'search','type'=>'get'));
  echo $this->Form->input('SearchTerm',array('label' => 'Find:'));
  echo $this->Form->input('FilterBy', array('type'=>'select', 'label'=>'Search:', 'options'=>$options));
  echo $this->Form->end('search'); 
?>  

*コントローラーで見つけやすいようにoptions名前をに変更したことに注意してください。FilterByまた、ビューでクリーンアップできるものが他にもあります。ただし、質問に対応するもののみを取り上げます。

次に、このコードを置き換える必要があります。

<tr ><?php //echo $this->Paginator->numbers(array('first' => 'First page')); ?></tr>
    <?php
    $urlParams = $this->params['url'];
    unset($urlParams['url']);
    $optionss=array('url' => array('?' => http_build_query($urlParams)));
    //$this->Paginator->options($optionss);
    $this->Paginator->settings['paramType'] = 'querystring';

    ?>

    <tr ><?php  //echo" << ".$this->Paginator->counter(
       // 'Page {:page} of {:pages}');
        ?></tr>

</table>

このコードで:

</table>
<p>
<?php
  $this->Paginator->options(array('url' => array_merge(array('SearchString' => $SearchString, 'FilterBy' => $FilterBy), $this->passedArgs)));

echo $this->Paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%')
));
?>  
</p>

<div class="paging">
    <?php echo $this->Paginator->prev('<< ' . __('previous'), array(), null, array('class'=>'disabled'));?>
 |  <?php echo $this->Paginator->numbers();?>
 |  <?php echo $this->Paginator->next(__('next') . ' >>', array(), null, array('class' => 'disabled'));?>
</div>

もちろん、ニーズに合わせてフォーマットを変更します。ただし、コードは、ページネーションに適用された検索語とフィルターオプションで期待どおりに機能するはずです。

幸運とハッピーコーディング!

于 2012-02-10T05:47:21.213 に答える