Fabien POTENCIER wrote:
> The biggest problem of a table widget IS the separation between what 
> belongs to which layer: the View, the Model, or the Controller. This 
> separation is very important and quite difficult to achieve. This is the 
> same kind of problem I tried to solve with the new form framework.

Here's a really simple mockup which might provide food for thought...

Conceptially, the idea is you instance a sfTable, add your rows (thereby 
'flattening' the data), and then you have a widget that is responsible 
for formatting the output...


in the action....

     $table = new sfTable();
     $ret = Doctrine_Query::create()
       ->from('Customer c')
       ->leftjoin('c.Property p')
       ->innerjoin('p.Key k')
       ->where('k.namespace = ?',
       ->limit(10)
       ->execute()
       ;
     foreach($ret as $r)
     {
       $table->addRow(array(
         'login' => $r['login']
       ));
     }
     $this->table = $table;


in the tempalte...

<?php  echo $table; ?>

the really basic code thrown together....


class sfTable
{
   private $_data;

   public function addRow($data)
   {
     $this->_data[] = $data;
   }

   public function getRows()
   {
     return $this->_data;
   }

   public function render()
   {
     $widget = new sfWidgetTable($this);
     return $widget->render();
   }

   public function __toString()
   {
     return $this->render();
   }
}

class sfWidgetTable
{
   private $_table;

   public function __construct($table)
   {
     $this->_table = $table;
   }

   public function render()
   {
     $ret = '';
     foreach($this->_table->getRows() as $r)
     {
       $ret .= $this->renderRow($r);
     }
     return $ret;
   }

   public function renderRow($row)
   {
     $ret = "<pre>";
     $ret .= print_r($row, true);
     $ret .= "</pre><hr />";
     return $ret;
   }

}



Here, you can see that you could override the 'renderRow()' function to 
do anything yo uwanted... here I'm just printing out <pre> tags and 
dumping.. but imagine something like this.


public function renderRow($row)
{
   // replace with some kinda alternating row magic, probably this
   // functinoality would be providedby the widget class, so you could
   // $this->alternating($class, $freqency) or something...
   $ret = '<tr class="myrow">';
   $ret .= '<td>'.
           $this->generateLink($row['username'], '@user_details') .
          '</td>'....

}


So, you have a class that's responsible for holing the table data 
(sfTable/controller) and one for printing it out (sfWidgetTable/view).

sfTable cuold be extended to sfTableDoctrine/sfTablePropel to handle 
automatic paging, ordering etc.

maybe even it could be grouped by something... sfLayout ? where you 
could create a widget that has the table, and the filte rform in one, 
and it all just magically works.


-- 

Ian P. Christian ~ http://pookey.co.uk

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony developers" group.
To post to this group, send email to symfony-devs@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to