0

Current Approach

Currently I render all my pagination results in a single element using a <table> that has a header, body and footer structure. The rendering style is very spreadsheet like and this one element can handle paginated results for multiple controllers.

The Problem

I need to now support configurable rendering styles for the paginated results. The two main styles are spreadsheet and pinterest.com style (by pinterest I refer to vertical columns of varying lengths).

How To Implement

I'm looking for an answer on how to implement this using CakePHP 2.2 view features. Blocks, themes, and nested views. So that as much of the code is dry, and the configured part only applies the styling that is different.

The code to render the values in each tablet cell, the record title, and details like that should all be separated from the code that renders it either as a table or pinterest (or what ever you call that style).

Challenges

Each method in Cake seems to present limitations. What approach bests deals with the following?

  • When each record is rendered, it will need different pre/post tags, and the same for each field in that record. Those tags are defined a lot by the style renderer.
  • I may need to add features in the future like AJAX editing of a field value, and shouldn't need to modify the style handlers. So the style renderer should just deal with style.
  • A lot of my style tags will involve wrapping presented data. What CakePHP method works best for that?
  • What's the best way to configure this? So that the paginate element knows which style to render.
4

2 回答 2

1

我最近不得不使用定义列表的无序列表来做到这一点。在保持代码 DRY 的同时执行此操作的关键是使用元素。元素是存在于文件夹 Views/Elements 中的 ctp 文件

在我的 index.ctp 中,我将表格更改为 ul 标签,将 tr 标签更改为 li 标签,并调用元素来处理渲染 dl。使用数组将对象及其类型传递给元素,剩下的可以用css完成

索引.ctp:

<ul><?php
  foreach ($blobs as $blob){
   echo $this->Html->tag('li',$this->element('dl',array('blob'=>$blob,'type'=>'Blob')));
  }
?></ul>

dl.ctp:

<dl class="<?php echo $type;?>"><?php
  foreach ($blob[$type] as $key => $v){
    echo $this->Html->tag('dt',$key);
    echo $this->Html->tag('dd',$v);
  }
?></dl>
于 2013-01-22T22:46:52.490 回答
0

您最好的选择可能是使用 CSS;你会惊讶于你能用它做什么。您甚至可以将表格从矩形布局“翻转”到垂直布局(例如在移动屏幕上),这似乎与您想要的很接近。

于 2013-01-21T23:37:58.810 回答