Allow \yii\console\widgets\Table to render empty table (#16865)

When headers provided but no columns.
Ref #16858
This commit is contained in:
Damian Dziaduch
2018-11-05 22:05:49 +01:00
committed by Alexander Makarov
parent 1fe3d61a3b
commit e11e3eb4c5
3 changed files with 22 additions and 1 deletions

View File

@ -82,6 +82,7 @@ Yii Framework 2 Change Log
- Enh #16839: Increase frequency of lock tries for `yii\mutex\FileMutex::acquireLock()` when $timeout is provided (rob006)
- Enh #16839: Add support for `$timeout` in `yii\mutex\PgsqlMutex::acquire()` (rob006)
- Bug #16828: `yii\console\controllers\MessageController::translator` recognized object' methods and functions calls as identical sets of tokens (erickskrauch)
- Bug #16858: Allow `\yii\console\widgets\Table` to render empty table when headers provided but no columns (damiandziaduch)
2.0.15.1 March 21, 2018

View File

@ -310,7 +310,11 @@ class Table extends Widget
$screenWidth = $this->getScreenWidth() - self::CONSOLE_SCROLLBAR_OFFSET;
$headerCount = count($this->_headers);
$rowColCount = max(array_map('count', $this->_rows));
if (empty($this->_rows)) {
$rowColCount = 0;
} else {
$rowColCount = max(array_map('count', $this->_rows));
}
$count = max($headerCount, $rowColCount);
for ($i = 0; $i < $count; $i++) {
$columns[] = ArrayHelper::getColumn($this->_rows, $i);