Hind Mesfaoyi
Hind Mesfaoyi

Reputation: 41

Sorting Data with CakePHP

sorry for the dumb question, but i just started to learn cakephp,

i have list of cars and I want to sorted by price,

this is my code

<!--bady-->
<section>
<div>
        <div class="sort_by">
        <div class="padding-none"> 
        <span class="title_sort"><strong>Sort by:</strong></span> 

        <div class="my-dropdown">
        <select name="price" class="css-" tabindex="1" >
            <option value="ASC">Prix croissant</option>
            <option value="DESK">Prix decroissant</option>
        </select>
        </div>

        </div>

        <div class="clearfix"></div>
        <div class="reselt_cars">

             //result content

            <div class="clearfix"></div>
        </div>

    </div>
 </div>
 </section>

i have no idea how to go from the dropdown to controller

Upvotes: 1

Views: 110

Answers (1)

Salines
Salines

Reputation: 5767

i have no idea how to go from the dropdown to controller

create sort links with html helper

https://book.cakephp.org/3.0/en/views/helpers/html.html#creating-links

<ul>
  <li><?= $this->Html->link('Prix croissant', ['action' => 'index', '?' => ['sort' => 'price', 'direction' => 'asc']]); ?></li>
  <li><?= $this->Html->link('Prix decroissant', ['action' => 'index', '?' => ['sort' => 'price', 'direction' => 'desc']]); ?></li>
</ul>

create sort links with paginator helper

https://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-sort-links

echo $this->Paginator->sort('user_id', null, ['direction' => 'desc']);

Upvotes: 1

Related Questions