Cakephp,如何使用分页创建网格和列表视图


Cakephp, how to create grid and list view using pagination?

我打算做的是改变视图(网格或列表)与cakephp。我所做的是:

$( document ).ready(function() {
    $(".lista_options #gridview").click(function(){
        $( "#content" ).addClass( 'cubos' );

    });
    $(".lista_options #listview").click(function(){
    $( "#content" ).removeClass( 'cubos' );

    });
});

这里的问题是,我有一个分页器,因为这个原因,当我改变页面,以获得更多的结果,我选择的视图不停留。我的问题是我如何改变我的视图模式并在所有分页期间保持不变?

任何建议都是好的。

使用cookie和(或)会话共享您的更改。当你点击在列表和网格之间切换时,保存对cookie的更改,在页面加载时读取cookie并使用其值。

EDIT: update code

使用jquery插件

添加:

$( document ).ready(function() {
$(".lista_options #gridview").click(function(){
    $( "#content" ).addClass( 'cubos' );
    $.cookie.raw = true;
    $.cookie('CakeCookie[switch]', 'grid', { expires: 7, path: '/' });
});
$(".lista_options #listview").click(function(){
$( "#content" ).removeClass( 'cubos' );
    $.cookie.raw = true;
    $.cookie('CakeCookie[switch]', 'list', { expires: 7, path: '/' });
});
});

有:beforeFilter ();

if($this->Cookie->check('switch')){
  $this->set('style', $this->Cookie->read('switch'));
}

index.ctp

<div class="<?php if($style == 'grid'){ ?> cubos <?php } ?>" > ...