【问题标题】:Cakephp Pagination in DropDown?下拉菜单中的 Cakephp 分页?
【发布时间】:2013-03-26 13:49:06
【问题描述】:

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

我希望我的用户使用我的过滤选项在相同的表单中选择排序顺序,所以当他们点击“发送”时,分页顺序已经设置。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                 
        )
    );

【问题讨论】:

    标签: cakephp pagination cakephp-2.0 form-helpers


    【解决方案1】:
        $(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'
    ));
    ?>
    

    【讨论】:

    • 感谢您提供此代码 sn-p,它可能会提供一些即时帮助。一个正确的解释would greatly improve 它的教育价值通过展示为什么这是一个很好的解决问题的方法,并将使它对未来有类似但不相同的问题的读者更有用。请edit您的答案添加解释,并说明适用的限制和假设。
    【解决方案2】:

    我会将选项的值更改为例如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] )
    ));
    

    可能有一种更优雅的方法可以做到这一点,但这应该可行。

    【讨论】:

      猜你喜欢
      • 2012-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-03
      • 1970-01-01
      • 1970-01-01
      • 2022-10-22
      • 1970-01-01
      相关资源
      最近更新 更多