mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
Merge pull request #674 from colares/ticket-2787
Add table attributes per column Fixes #2787
This commit is contained in:
commit
119377422e
2 changed files with 19 additions and 2 deletions
|
@ -1505,6 +1505,18 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
$result = $this->Html->tableHeaders(array('ID', 'Name', 'Date'));
|
||||
$expected = array('<tr', '<th', 'ID', '/th', '<th', 'Name', '/th', '<th', 'Date', '/th', '/tr');
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Html->tableHeaders(array('ID', array('Name' => array('class' => 'highlight')), 'Date'));
|
||||
$expected = array('<tr', '<th', 'ID', '/th', '<th class="highlight"', 'Name', '/th', '<th', 'Date', '/th', '/tr');
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Html->tableHeaders(array('ID', array('Name' => array('class' => 'highlight', 'width' => '120px')), 'Date'));
|
||||
$expected = array('<tr', '<th', 'ID', '/th', '<th class="highlight" width="120px"', 'Name', '/th', '<th', 'Date', '/th', '/tr');
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Html->tableHeaders(array('ID', array('Name' => array()), 'Date'));
|
||||
$expected = array('<tr', '<th', 'ID', '/th', '<th', 'Name', '/th', '<th', 'Date', '/th', '/tr');
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -787,7 +787,8 @@ class HtmlHelper extends AppHelper {
|
|||
/**
|
||||
* Returns a row of formatted and named TABLE headers.
|
||||
*
|
||||
* @param array $names Array of tablenames.
|
||||
* @param array $names Array of tablenames. Each tablename also can be a key that points to an array with a set
|
||||
* of attributes to its specific tag
|
||||
* @param array $trOptions HTML options for TR elements.
|
||||
* @param array $thOptions HTML options for TH elements.
|
||||
* @return string Completed table headers
|
||||
|
@ -796,7 +797,11 @@ class HtmlHelper extends AppHelper {
|
|||
public function tableHeaders($names, $trOptions = null, $thOptions = null) {
|
||||
$out = array();
|
||||
foreach ($names as $arg) {
|
||||
if (!is_array($arg)) {
|
||||
$out[] = sprintf($this->_tags['tableheader'], $this->_parseAttributes($thOptions), $arg);
|
||||
} else {
|
||||
$out[] = sprintf($this->_tags['tableheader'], $this->_parseAttributes(current($arg)), key($arg));
|
||||
}
|
||||
}
|
||||
return sprintf($this->_tags['tablerow'], $this->_parseAttributes($trOptions), join(' ', $out));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue