0

我正在寻找一种方法来处理下拉菜单中的分页选项。

我希望我的用户使用我的过滤选项以相同的形式选择排序顺序,所以当他们点击“发送”时,分页顺序已经设置.orm

例如:

$this->Form->input('paginationorder',array(
        'label' => 'order',
        'options' => array(
           'sort:id/direction:desc' => 'New Items, desc',
           'sort:id/direction:asc' => 'New Items,asc',
            ),
        'div' => false                 
        )
    );
4

2 回答 2

2
    $(function() {
       $('#sort-properties').change(function() {   // replace the ID_OF_YOUR_SELECT_BOX with the id to your select box given by Cake
           var price = $(this).val();
           window.location = baseUrl + 'properties/property_view/'+price;
        });
    });



<?php

echo $this->Form->input('orderby', array(
    'id' => 'sort-properties',
    'options' => array(
        'sort:sale_rent_price/direction:asc' => 'Sort by Price Low to High',
        'sort:sale_rent_price/direction:desc' => 'Sort by Price High to Low',
        'sort:created/direction:asc' => 'Sort by Date Old to New',
        'sort:created/direction:desc' => 'Sort by Date New to Old'

    ),
    'label' => false,
    'empty' => 'Default Order'
));
?>
于 2017-05-18T10:48:26.623 回答
0

I would change the values of the options to e.g. fieldname.desc, like :

$this->Form->input('paginationorder',array(
        'label' => 'order',
        'options' => array(
           'id.desc' => 'New Items, desc',
           'id.asc' => 'New Items,asc',
            ),
        'div' => false                 
        )
    );

Afterwards in the controller put the values to an array via the explode method:

$order = explode(".", $this->request->data['Model']['field']);

then you can use the values in your find condition, like:

$result = $this->Model->find('all', array(
    'order' => array( $order[0] => $order[1] )
));

There is propably a more elegant way to make this, but this should work.

于 2013-04-04T13:50:46.957 回答