June 9, 2006
A Radio List in a table for CakePHP
I wanted to present a range of choices in a nicely formatted table and couldn't see helper to do the job - so this is my first snippet for Cake PHP. I doubt it's perfectly cake (for instance I do the header row myself rather than using the html helper, and I concatenate a string rather than building an array)
In this instance I added the function radioTable to a helper called "fed" and gave it the standard model and field variables.
To call it I just use
where the second parameter is the nice labels for my table.
PHP:
-
function radioTable($fieldName, $headers, $options, $htmlAttributes=null,$return=false)
-
{
-
$this->setFormTag($fieldName);
-
$value = (isset($htmlAttributes['value']))? $htmlAttributes['value']: $this->Html->tagValue($fieldName);
-
$out = '<table><tbody>';
-
{
-
$out .= '<tr>';
-
foreach($headers as $th) $out .= "<th>{$th}</th>\n";
-
$out .= '</tr>';
-
}
-
$thisTag = "<tr><td>\n{$this->Html->tags['radio']}\n</td>\n";
-
-
foreach ($options as $holder)
-
{
-
{
-
$thisHolder[] = $thisItem;
-
}
-
else $thisHolder = $holder;
-
-
foreach ($thisHolder as $item)
-
{
-
{
-
// will have changed so need to rework
-
}
-
else $thisItem = $item;
-
-
$optValue = $thisItem[$keys[0]];
-
$optValue==$value? $optionsHere['checked'] = 'checked': null;
-
$parsedOptions = $this->Html->parseHtmlOptions(array_merge($htmlAttributes, $optionsHere), null, '', ' ');
-
$individualTagName = "{$this->field}_{$optValue}";
-
-
//start on the second element in the array
-
for($i=1; $i <$cnt; $i++) $out .= "<td><label for='{$individualTagName}'>{$item[$keys[$i]]}</label>\n";
-
$out .= '</tr>';
-
}
-
}
-
$out .= '</tbody></table>';
-
-
return $this->output($out? $out: null, $return);
-
}//radioTable


how you use this example I can not set it up
Comment by isaac — July 3, 2006 @ 9:17 am