HtmlHelper::tableCells() now accepts a fifth parameter $continueOddEven, which by default is true, thereby not affecting current behaviour. When false, $count will not be static, and will therefore start from zero, giving correct odd and even values if they are passed. Fixes #4222

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7003 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
joelmoss 2008-05-22 09:13:23 +00:00
parent 9b514352dc
commit 17c542d76d
2 changed files with 41 additions and 2 deletions

View file

@ -480,16 +480,26 @@ class HtmlHelper extends AppHelper {
* @param bool $useCount adds class "column-$i"
* @return string Formatted HTML
*/
function tableCells($data, $oddTrOptions = null, $evenTrOptions = null, $useCount = false) {
function tableCells($data, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true) {
if (empty($data[0]) || !is_array($data[0])) {
$data = array($data);
}
static $count = 0;
if ($oddTrOptions === true) {
$useCount = true;
$oddTrOptions = null;
}
if ($evenTrOptions === false) {
$continueOddEven = false;
$evenTrOptions = null;
}
if ($continueOddEven) {
static $count = 0;
} else {
$count = 0;
}
foreach ($data as $line) {
$count++;
$cellsOut = array();

View file

@ -639,6 +639,35 @@ class HtmlHelperTest extends CakeTestCase {
'/tr'
);
$this->assertTags($result, $expected);
$tr = array(
array('td content 1', 'td content 2', 'td content 3'),
array('td content 1', 'td content 2', 'td content 3'),
array('td content 1', 'td content 2', 'td content 3')
);
$result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
$expected = "<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>";
$this->assertEqual($result, $expected);
$tr = array(
array('td content 1', 'td content 2', 'td content 3'),
array('td content 1', 'td content 2', 'td content 3'),
array('td content 1', 'td content 2', 'td content 3'),
array('td content 1', 'td content 2', 'td content 3')
);
$result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
$expected = "<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>";
$this->assertEqual($result, $expected);
$tr = array(
array('td content 1', 'td content 2', 'td content 3'),
array('td content 1', 'td content 2', 'td content 3'),
array('td content 1', 'td content 2', 'td content 3')
);
$this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'));
$result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'), false, false);
$expected = "<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>";
$this->assertEqual($result, $expected);
}
function testTag() {