2013-04-04 61 views
0

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

我想我的用户我的过滤选项,选择在同一形式的排列顺序,所以当他们点击“发送”,页码顺序已经set.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     
     ) 
    ); 

回答

0

我会将选项的值更改为例如fieldname.desc,如:

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

那么您可以在您的查找条件中使用的值,比如:

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

然后在控制器通过爆炸方法把值到一个数组

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

有一种更合适的方式来做到这一点,但这应该工作。

0
$(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' 
)); 
?> 
+0

谢谢你的代码片段,它可能会提供一些即时的帮助。通过展示*为什么*这是一个很好的解决方案,对未来的读者会有更好的解决方案,这将为它的教育价值提供一个合适的解释[//大大提高](// meta.stackexchange.com/q/114762)但不完全相同的问题。请编辑您的答案以添加解释,并指出适用的限制和假设。 – 2017-05-18 10:55:58