Pagination with placeholder cakephp 3.X

445 Views Asked by At

I have searched for 2 days, but found no answer. I use a query with placeholders (%$string%) for searching customers.

In the Controller:

  ` public function searchName()
        {      
            $data = $this->Kunden->find()->where([
                'Kunden.name LIKE' => '%'.\filter_input(\INPUT_POST, 'name', \FILTER_DEFAULT).'%']);
        $this->set(\compact('data'), $this->paginate($data));
        $this->set('_serialize', ['data']);

        }
` 

In the search_name.ctp:

    <?php foreach ($data as $suche): ?>
         <tr>
            <td><?= $this->Number->format($suche->Kundennummer,['precision' => 0, 'pattern' => '####']) ?></td>
            <td><?= h($suche->Anrede) ?></td>
            <td><?= h($suche->Name) ?></td>
            <td><?= h($suche->Vorname) ?></td>
            <td><?= h($suche->Ansprechpartner) ?></td>
            <td><?= h($suche->Strasse_Nr) ?></td>
            <td><?= h($suche->PLZ) ?></td>
            <td class="actions">
                <?= $this->Html->link(__('View'), ['action' => 'view', $suche->Kundennummer]) ?>
                <?= $this->Html->link(__('Edit'), ['action' => 'edit', $suche->Kundennummer]) ?>

            </td>
        </tr>

    <?php endforeach; ?>
    </tbody>
    </table>
   <?php
        $this->Paginator->options(array(
        'url' => array(
        'data' => $data)));
      ?>
    <div class="paginator">
        <ul class="pagination">

            <?= $this->Paginator->first('<< ' . __('erste Seite')) ?>
            <?= $this->Paginator->prev('< ' . __('vor')) ?>
            <?= $this->Paginator->numbers() ?>
            <?= $this->Paginator->next(__('next') . ' >') ?>
            <?= $this->Paginator->last('>> ' . __('letzte Seite')) ?>
            <?= $this->Paginator->number(' ' . __('gehe zu Seite:')) ?>
        </ul>
        <p><?= $this->Paginator->counter() ?></p>
    </div>
</div>

The first page shows a list of customers found by %$string%, but in the next pages I get all customers from the table.

I print the array $data foreach pagebuildung, the value of the placeholder changes from the first to the second page.

first page: ... LIMIT 10 OFFSET 0 [params] => Array ( [:c0] => Array ( [value] => %ab% [type] => [placeholder] => c0 )...

second page: ... LIMIT 10 OFFSET 10 [params] => Array ( [:c0] => Array ( [value] => %% [type] => [placeholder] => c0 ) ...

What can I do to keep the value ?

Thank you for help ..

0

There are 0 best solutions below