我正在寻找一种方法,在下拉菜单中处理分页选项。
我希望我的用户使用我的过滤选项以相同的形式选择排序顺序,因此当他们点击“发送”时,已经设置了分页顺序。范围
e.g。像:
$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
)
);
答案 0 :(得分: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'
));
?>
答案 1 :(得分:0)
我会将选项的值更改为例如fieldname.desc,如:
$this->Form->input('paginationorder',array(
'label' => 'order',
'options' => array(
'id.desc' => 'New Items, desc',
'id.asc' => 'New Items,asc',
),
'div' => false
)
);
然后在控制器中通过explode方法将值放入数组:
$order = explode(".", $this->request->data['Model']['field']);
然后您可以使用查找条件中的值,例如:
$result = $this->Model->find('all', array(
'order' => array( $order[0] => $order[1] )
));
有一个更优雅的方法可以做到这一点,但这应该有用。