From 02581c59e746634cdb45f4bffca663af2f73c5ac Mon Sep 17 00:00:00 2001 From: creocoder Date: Wed, 31 Jul 2013 18:56:36 +0400 Subject: [PATCH 01/45] Make ActiveRecord::getNamespacedClass() static --- framework/yii/db/ActiveRecord.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/yii/db/ActiveRecord.php b/framework/yii/db/ActiveRecord.php index 3ad5bd3..a047270 100644 --- a/framework/yii/db/ActiveRecord.php +++ b/framework/yii/db/ActiveRecord.php @@ -440,7 +440,7 @@ class ActiveRecord extends Model public function hasOne($class, $link) { return new ActiveRelation(array( - 'modelClass' => $this->getNamespacedClass($class), + 'modelClass' => static::getNamespacedClass($class), 'primaryModel' => $this, 'link' => $link, 'multiple' => false, @@ -478,7 +478,7 @@ class ActiveRecord extends Model public function hasMany($class, $link) { return new ActiveRelation(array( - 'modelClass' => $this->getNamespacedClass($class), + 'modelClass' => static::getNamespacedClass($class), 'primaryModel' => $this, 'link' => $link, 'multiple' => true, @@ -1400,10 +1400,10 @@ class ActiveRecord extends Model * @param string $class the class name to be namespaced * @return string the namespaced class name */ - protected function getNamespacedClass($class) + protected static function getNamespacedClass($class) { if (strpos($class, '\\') === false) { - $reflector = new \ReflectionClass($this); + $reflector = new \ReflectionClass(static::className()); return $reflector->getNamespaceName() . '\\' . $class; } else { return $class; From 58083f6ed0197f80b91647a339d51cd42bd332ab Mon Sep 17 00:00:00 2001 From: Michael Bodnarchuk Date: Wed, 31 Jul 2013 22:39:13 +0300 Subject: [PATCH 02/45] A simple patch to get AspectMock and Go Aop working with Yii2 This is a very tiny patch that changes nothing in code logic, but is required to get [AspectMock](https://github.com/Codeception/AspectMock) and Go Aop working with Yii2. Go Aop is processing all `include` and `require` directives, replacing them with its filters. Unfortunately it doesn't play well with one-liners. So I had to break the code into few lines to get that working. I was trying to fix this issue in [Go Aop](https://github.com/lisachenko/go-aop-php/pull/78) but looks like, the only option is to fix that in Yii2. AspectMock can dramaticly improve unit testing in Yii2, and I plan to do a blogpost with tutorial about it. --- framework/yii/helpers/SecurityBase.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/framework/yii/helpers/SecurityBase.php b/framework/yii/helpers/SecurityBase.php index 9b743c4..69f7ee8 100644 --- a/framework/yii/helpers/SecurityBase.php +++ b/framework/yii/helpers/SecurityBase.php @@ -120,7 +120,10 @@ class SecurityBase static $keys; $keyFile = Yii::$app->getRuntimePath() . '/keys.php'; if ($keys === null) { - $keys = is_file($keyFile) ? require($keyFile) : array(); + $keys = array(); + if (is_file($keyFile)) { + $keys = require($keyFile); + } } if (!isset($keys[$name])) { $keys[$name] = static::generateRandomKey($length); From 2a08297ac836794bd848ddb962bdf9141da40cf6 Mon Sep 17 00:00:00 2001 From: davert Date: Wed, 31 Jul 2013 22:47:45 +0300 Subject: [PATCH 03/45] formatting fix --- framework/yii/helpers/SecurityBase.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/yii/helpers/SecurityBase.php b/framework/yii/helpers/SecurityBase.php index 69f7ee8..ca7978d 100644 --- a/framework/yii/helpers/SecurityBase.php +++ b/framework/yii/helpers/SecurityBase.php @@ -120,10 +120,10 @@ class SecurityBase static $keys; $keyFile = Yii::$app->getRuntimePath() . '/keys.php'; if ($keys === null) { - $keys = array(); + $keys = array(); if (is_file($keyFile)) { - $keys = require($keyFile); - } + $keys = require($keyFile); + } } if (!isset($keys[$name])) { $keys[$name] = static::generateRandomKey($length); From 7f2d2da52c476143cd270d9e73345ff26a841c7c Mon Sep 17 00:00:00 2001 From: davert Date: Wed, 31 Jul 2013 23:01:11 +0300 Subject: [PATCH 04/45] formatting fix --- framework/yii/helpers/SecurityBase.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/yii/helpers/SecurityBase.php b/framework/yii/helpers/SecurityBase.php index ca7978d..05b2682 100644 --- a/framework/yii/helpers/SecurityBase.php +++ b/framework/yii/helpers/SecurityBase.php @@ -120,10 +120,10 @@ class SecurityBase static $keys; $keyFile = Yii::$app->getRuntimePath() . '/keys.php'; if ($keys === null) { - $keys = array(); + $keys = array(); if (is_file($keyFile)) { - $keys = require($keyFile); - } + $keys = require($keyFile); + } } if (!isset($keys[$name])) { $keys[$name] = static::generateRandomKey($length); From 4b9e9654547cca70f02c97808d5c606931251715 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Thu, 1 Aug 2013 08:26:54 -0400 Subject: [PATCH 05/45] GridView WIP --- framework/yii/widgets/GridView.php | 326 ++++++++++++++++++++++++++ framework/yii/widgets/grid/CheckboxColumn.php | 191 +++++++++++++++ framework/yii/widgets/grid/Column.php | 147 ++++++++++++ framework/yii/widgets/grid/DataColumn.php | 95 ++++++++ 4 files changed, 759 insertions(+) create mode 100644 framework/yii/widgets/GridView.php create mode 100644 framework/yii/widgets/grid/CheckboxColumn.php create mode 100644 framework/yii/widgets/grid/Column.php create mode 100644 framework/yii/widgets/grid/DataColumn.php diff --git a/framework/yii/widgets/GridView.php b/framework/yii/widgets/GridView.php new file mode 100644 index 0000000..98b4884 --- /dev/null +++ b/framework/yii/widgets/GridView.php @@ -0,0 +1,326 @@ + + * @since 2.0 + */ +class GridView extends ListViewBase +{ + const FILTER_POS_HEADER = 'header'; + const FILTER_POS_FOOTER = 'footer'; + const FILTER_POS_BODY = 'body'; + + public $caption; + public $captionOptions = array(); + public $tableOptions = array('class' => 'table table-striped table-bordered'); + public $headerRowOptions = array(); + public $footerRowOptions = array(); + public $beforeRow; + public $afterRow; + public $showHeader = true; + public $showFooter = false; + /** + * @var array|Closure + */ + public $rowOptions = array(); + /** + * @var array|Formatter the formatter used to format model attribute values into displayable texts. + * This can be either an instance of [[Formatter]] or an configuration array for creating the [[Formatter]] + * instance. If this property is not set, the "formatter" application component will be used. + */ + public $formatter; + /** + * @var array grid column configuration. Each array element represents the configuration + * for one particular grid column which can be either a string or an array. + * + * When a column is specified as a string, it should be in the format of "name:type:header", + * where "type" and "header" are optional. A {@link CDataColumn} instance will be created in this case, + * whose {@link CDataColumn::name}, {@link CDataColumn::type} and {@link CDataColumn::header} + * properties will be initialized accordingly. + * + * When a column is specified as an array, it will be used to create a grid column instance, where + * the 'class' element specifies the column class name (defaults to {@link CDataColumn} if absent). + * Currently, these official column classes are provided: {@link CDataColumn}, + * {@link CLinkColumn}, {@link CButtonColumn} and {@link CCheckBoxColumn}. + */ + public $columns = array(); + /** + * @var string the layout that determines how different sections of the list view should be organized. + * The following tokens will be replaced with the corresponding section contents: + * + * - `{summary}`: the summary section. See [[renderSummary()]]. + * - `{items}`: the list items. See [[renderItems()]]. + * - `{sorter}`: the sorter. See [[renderSorter()]]. + * - `{pager}`: the pager. See [[renderPager()]]. + */ + public $layout = "{summary}\n{pager}{items}\n{pager}"; + public $emptyCell = ' '; + /** + * @var \yii\base\Model the model instance that keeps the user-entered filter data. When this property is set, + * the grid view will enable column-based filtering. Each data column by default will display a text field + * at the top that users can fill in to filter the data. + * Note that in order to show an input field for filtering, a column must have its {@link CDataColumn::name} + * property set or have {@link CDataColumn::filter} as the HTML code for the input field. + * When this property is not set (null) the filtering is disabled. + */ + public $filterModel; + /** + * @var string whether the filters should be displayed in the grid view. Valid values include: + *
    + *
  • header: the filters will be displayed on top of each column's header cell.
  • + *
  • body: the filters will be displayed right below each column's header cell.
  • + *
  • footer: the filters will be displayed below each column's footer cell.
  • + *
+ */ + public $filterPosition = 'body'; + public $filterOptions = array('class' => 'filters'); + + /** + * Initializes the grid view. + * This method will initialize required property values and instantiate {@link columns} objects. + */ + public function init() + { + parent::init(); + if ($this->formatter == null) { + $this->formatter = Yii::$app->getFormatter(); + } elseif (is_array($this->formatter)) { + $this->formatter = Yii::createObject($this->formatter); + } + if (!$this->formatter instanceof Formatter) { + throw new InvalidConfigException('The "formatter" property must be either a Format object or a configuration array.'); + } + + $this->initColumns(); + } + + /** + * Renders the data items for the grid view. + */ + public function renderItems() + { + $content = array_filter(array( + $this->renderCaption(), + $this->renderColumnGroup(), + $this->showHeader ? $this->renderTableHeader() : false, + $this->showFooter ? $this->renderTableFooter() : false, + $this->renderTableBody(), + )); + return Html::tag('table', implode("\n", $content), $this->tableOptions); + } + + public function renderCaption() + { + if (!empty($this->caption)) { + return Html::tag('caption', $this->caption, $this->captionOptions); + } else { + return false; + } + } + + public function renderColumnGroup() + { + $requireColumnGroup = false; + foreach ($this->columns as $column) { + /** @var \yii\widgets\grid\Column $column */ + if (!empty($column->options)) { + $requireColumnGroup = true; + break; + } + } + if ($requireColumnGroup) { + $cols = array(); + foreach ($this->columns as $column) { + $cols[] = Html::tag('col', '', $column->options); + } + return Html::tag('colgroup', implode("\n", $cols)); + } else { + return false; + } + } + + /** + * Renders the table header. + * @return string the rendering result + */ + public function renderTableHeader() + { + $cells = array(); + foreach ($this->columns as $column) { + /** @var \yii\widgets\grid\Column $column */ + $cells[] = $column->renderHeaderCell(); + } + $content = implode('', $cells); + if ($this->filterPosition == self::FILTER_POS_HEADER) { + $content = $this->renderFilters() . $content; + } elseif ($this->filterPosition == self::FILTER_POS_BODY) { + $content .= $this->renderFilters(); + } + return "\n" . Html::tag('tr', $content, $this->headerRowOptions) . "\n"; + } + + /** + * Renders the table footer. + * @return string the rendering result + */ + public function renderTableFooter() + { + $cells = array(); + foreach ($this->columns as $column) { + /** @var \yii\widgets\grid\Column $column */ + $cells[] = $column->renderFooterCell(); + } + $content = implode('', $cells); + if ($this->filterPosition == self::FILTER_POS_FOOTER) { + $content .= $this->renderFilters(); + } + return "\n" . Html::tag('tr', $content, $this->footerRowOptions) . "\n"; + } + + /** + * Renders the filter. + */ + public function renderFilters() + { + if ($this->filterModel !== null) { + $cells = array(); + foreach ($this->columns as $column) { + /** @var \yii\widgets\grid\Column $column */ + $cells[] = $column->renderFilterCell(); + } + return Html::tag('tr', implode('', $cells), $this->filterOptions); + } else { + return ''; + } + } + + /** + * Renders the table body. + * @return string the rendering result + */ + public function renderTableBody() + { + $items = array_values($this->dataProvider->getItems()); + $keys = $this->dataProvider->getKeys(); + $rows = array(); + foreach ($items as $index => $item) { + $key = $keys[$index]; + if ($this->beforeRow !== null) { + $row = call_user_func($this->beforeRow, $item, $key, $index); + if (!empty($row)) { + $rows[] = $row; + } + } + + $rows[] = $this->renderTableRow($item, $key, $index); + + if ($this->afterRow !== null) { + $row = call_user_func($this->afterRow, $item, $key, $index); + if (!empty($row)) { + $rows[] = $row; + } + } + } + return "\n" . implode("\n", $rows) . "\n"; + } + + /** + * Renders a table row with the given data item and key. + * @param mixed $item the data item + * @param mixed $key the key associated with the data item + * @param integer $index the zero-based index of the data item among the item array returned by [[dataProvider]]. + * @return string the rendering result + */ + public function renderTableRow($item, $key, $index) + { + $cells = array(); + /** @var \yii\widgets\grid\Column $column */ + foreach ($this->columns as $column) { + $cells[] = $column->renderDataCell($item, $index); + } + if ($this->rowOptions instanceof Closure) { + $options = call_user_func($this->rowOptions, $item, $key, $index); + } else { + $options = $this->rowOptions; + } + $options['data-key'] = $key; + return Html::tag('tr', implode('', $cells), $options); + } + + /** + * Creates column objects and initializes them. + */ + protected function initColumns() + { + if (empty($this->columns)) { + $this->guessColumns(); + } + $id = $this->getId(); + foreach ($this->columns as $i => $column) { + if (is_string($column)) { + $column = $this->createDataColumn($column); + } else { + $column = Yii::createObject(array_merge(array( + 'class' => DataColumn::className(), + 'grid' => $this, + ), $column)); + } + if (!$column->visible) { + unset($this->columns[$i]); + continue; + } + if ($column->id === null) { + $column->id = $id . '_c' . $i; + } + $this->columns[$i] = $column; + } + } + + /** + * Creates a {@link CDataColumn} based on a shortcut column specification string. + * @param string $text the column specification string + * @return DataColumn the column instance + * @throws InvalidConfigException if the column specification is invalid + */ + protected function createDataColumn($text) + { + if (!preg_match('/^(\w+)(\s*:\s*(\w+))?$/', $text, $matches)) { + throw new InvalidConfigException('The column must be specified in the format of "Attribute" or "Attribute:Type"'); + } + return Yii::createObject(array( + 'class' => DataColumn::className(), + 'grid' => $this, + 'attribute' => $matches[1], + 'type' => isset($matches[3]) ? $matches[3] : 'text', + )); + } + + protected function guessColumns() + { + $items = $this->dataProvider->getItems(); + $item = reset($items); + if (is_array($item) || is_object($item)) { + foreach ($item as $name => $value) { + $this->columns[] = $name; + } + } else { + throw new InvalidConfigException('Unable to generate columns from data.'); + } + } +} diff --git a/framework/yii/widgets/grid/CheckboxColumn.php b/framework/yii/widgets/grid/CheckboxColumn.php new file mode 100644 index 0000000..e6bb327 --- /dev/null +++ b/framework/yii/widgets/grid/CheckboxColumn.php @@ -0,0 +1,191 @@ + + * @since 2.0 + */ +class CheckboxColumn extends Column +{ + public $checked; + /** + * @var string a PHP expression that will be evaluated for every data cell and whose result will + * determine if checkbox for each data cell is disabled. In this expression, you can use the following variables: + *
    + *
  • $row the row number (zero-based)
  • + *
  • $data the data model for the row
  • + *
  • $this the column object
  • + *
+ * The PHP expression will be evaluated using {@link evaluateExpression}. + * + * A PHP expression can be any PHP code that has a value. To learn more about what an expression is, + * please refer to the {@link http://www.php.net/manual/en/language.expressions.php php manual}. + * + * Note that expression result will overwrite value set with checkBoxHtmlOptions['disabled']. + * @since 1.1.13 + */ + public $disabled; + /** + * @var array the HTML options for the data cell tags. + */ + public $htmlOptions = array('class' => 'checkbox-column'); + /** + * @var array the HTML options for the header cell tag. + */ + public $headerHtmlOptions = array('class' => 'checkbox-column'); + /** + * @var array the HTML options for the footer cell tag. + */ + public $footerHtmlOptions = array('class' => 'checkbox-column'); + /** + * @var array the HTML options for the checkboxes. + */ + public $checkBoxHtmlOptions = array(); + /** + * @var integer the number of rows that can be checked. + * Possible values: + *
    + *
  • 0 - the state of the checkbox cannot be changed (read-only mode)
  • + *
  • 1 - only one row can be checked. Checking a checkbox has nothing to do with selecting the row
  • + *
  • 2 or more - multiple checkboxes can be checked. Checking a checkbox has nothing to do with selecting the row
  • + *
  • null - {@link CGridView::selectableRows} is used to control how many checkboxes can be checked. + * Checking a checkbox will also select the row.
  • + *
+ * You may also call the JavaScript function $(gridID).yiiGridView('getChecked', columnID) + * to retrieve the key values of the checked rows. + * @since 1.1.6 + */ + public $selectableRows = null; + /** + * @var string the template to be used to control the layout of the header cell. + * The token "{item}" is recognized and it will be replaced with a "check all" checkbox. + * By default if in multiple checking mode, the header cell will display an additional checkbox, + * clicking on which will check or uncheck all of the checkboxes in the data cells. + * See {@link selectableRows} for more details. + * @since 1.1.11 + */ + public $headerTemplate = '{item}'; + + /** + * Initializes the column. + * This method registers necessary client script for the checkbox column. + */ + public function init() + { + if (isset($this->checkBoxHtmlOptions['name'])) { + $name = $this->checkBoxHtmlOptions['name']; + } else { + $name = $this->id; + if (substr($name, -2) !== '[]') { + $name .= '[]'; + } + $this->checkBoxHtmlOptions['name'] = $name; + } + $name = strtr($name, array('[' => "\\[", ']' => "\\]")); + + if ($this->selectableRows === null) { + if (isset($this->checkBoxHtmlOptions['class'])) { + $this->checkBoxHtmlOptions['class'] .= ' select-on-check'; + } else { + $this->checkBoxHtmlOptions['class'] = 'select-on-check'; + } + return; + } + + $cball = $cbcode = ''; + if ($this->selectableRows == 0) { + //.. read only + $cbcode = "return false;"; + } elseif ($this->selectableRows == 1) { + //.. only one can be checked, uncheck all other + $cbcode = "jQuery(\"input:not(#\"+this.id+\")[name='$name']\").prop('checked',false);"; + } elseif (strpos($this->headerTemplate, '{item}') !== false) { + //.. process check/uncheck all + $cball = <<id}_all',function() { + var checked=this.checked; + jQuery("input[name='$name']:enabled").each(function() {this.checked=checked;}); +}); + +CBALL; + $cbcode = "jQuery('#{$this->id}_all').prop('checked', jQuery(\"input[name='$name']\").length==jQuery(\"input[name='$name']:checked\").length);"; + } + + if ($cbcode !== '') { + $js = $cball; + $js .= <<getClientScript()->registerScript(__CLASS__ . '#' . $this->id, $js); + } + } + + /** + * Renders the header cell content. + * This method will render a checkbox in the header when {@link selectableRows} is greater than 1 + * or in case {@link selectableRows} is null when {@link CGridView::selectableRows} is greater than 1. + */ + protected function renderHeaderCellContent() + { + if (trim($this->headerTemplate) === '') { + echo $this->grid->blankDisplay; + return; + } + + $item = ''; + if ($this->selectableRows === null && $this->grid->selectableRows > 1) { + $item = CHtml::checkBox($this->id . '_all', false, array('class' => 'select-on-check-all')); + } elseif ($this->selectableRows > 1) { + $item = CHtml::checkBox($this->id . '_all', false); + } else { + ob_start(); + parent::renderHeaderCellContent(); + $item = ob_get_clean(); + } + + echo strtr($this->headerTemplate, array( + '{item}' => $item, + )); + } + + /** + * Renders the data cell content. + * This method renders a checkbox in the data cell. + * @param integer $row the row number (zero-based) + * @param mixed $data the data associated with the row + */ + protected function renderDataCellContent($row, $data) + { + if ($this->value !== null) { + $value = $this->evaluateExpression($this->value, array('data' => $data, 'row' => $row)); + } elseif ($this->name !== null) { + $value = CHtml::value($data, $this->name); + } else { + $value = $this->grid->dataProvider->keys[$row]; + } + + $checked = false; + if ($this->checked !== null) { + $checked = $this->evaluateExpression($this->checked, array('data' => $data, 'row' => $row)); + } + + $options = $this->checkBoxHtmlOptions; + if ($this->disabled !== null) { + $options['disabled'] = $this->evaluateExpression($this->disabled, array('data' => $data, 'row' => $row)); + } + + $name = $options['name']; + unset($options['name']); + $options['value'] = $value; + $options['id'] = $this->id . '_' . $row; + echo CHtml::checkBox($name, $checked, $options); + } +} diff --git a/framework/yii/widgets/grid/Column.php b/framework/yii/widgets/grid/Column.php new file mode 100644 index 0000000..8cb692d --- /dev/null +++ b/framework/yii/widgets/grid/Column.php @@ -0,0 +1,147 @@ + + * @since 2.0 + */ +class Column extends Object +{ + /** + * @var string the ID of this column. This value should be unique among all grid view columns. + * If this is not set, it will be assigned one automatically. + */ + public $id; + /** + * @var GridView the grid view object that owns this column. + */ + public $grid; + /** + * @var string the header cell content. Note that it will not be HTML-encoded. + */ + public $header; + /** + * @var string the footer cell content. Note that it will not be HTML-encoded. + */ + public $footer; + /** + * @var callable + */ + public $content; + /** + * @var boolean whether this column is visible. Defaults to true. + */ + public $visible = true; + public $options = array(); + public $headerOptions = array(); + /** + * @var array|\Closure + */ + public $bodyOptions = array(); + public $footerOptions = array(); + /** + * @var array the HTML attributes for the filter cell tag. + */ + public $filterOptions=array(); + + + /** + * Renders the header cell. + */ + public function renderHeaderCell() + { + return Html::tag('th', $this->renderHeaderCellContent(), $this->headerOptions); + } + + /** + * Renders the footer cell. + */ + public function renderFooterCell() + { + return Html::tag('td', $this->renderFooterCellContent(), $this->footerOptions); + } + + /** + * Renders a data cell. + * @param mixed $item the data item + * @param integer $index the zero-based index of the data item among the item array returned by [[dataProvider]]. + * @return string the rendering result + */ + public function renderDataCell($item, $index) + { + if ($this->bodyOptions instanceof Closure) { + $options = call_user_func($this->bodyOptions, $item, $index, $this); + } else { + $options = $this->bodyOptions; + } + return Html::tag('td', $this->renderDataCellContent($item, $index), $options); + } + + /** + * Renders the filter cell. + */ + public function renderFilterCell() + { + return Html::tag('td', $this->renderFilterCellContent(), $this->filterOptions); + } + + /** + * Renders the header cell content. + * The default implementation simply renders {@link header}. + * This method may be overridden to customize the rendering of the header cell. + * @return string the rendering result + */ + protected function renderHeaderCellContent() + { + return trim($this->header) !== '' ? $this->header : $this->grid->emptyCell; + } + + /** + * Renders the footer cell content. + * The default implementation simply renders {@link footer}. + * This method may be overridden to customize the rendering of the footer cell. + * @return string the rendering result + */ + protected function renderFooterCellContent() + { + return trim($this->footer) !== '' ? $this->footer : $this->grid->emptyCell; + } + + /** + * Renders the data cell content. + * @param mixed $item the data item + * @param integer $index the zero-based index of the data item among the item array returned by [[dataProvider]]. + * @return string the rendering result + */ + protected function renderDataCellContent($item, $index) + { + if ($this->content !== null) { + return call_user_func($this->content, $item, $index, $this); + } else { + return $this->grid->emptyCell; + } + } + + /** + * Renders the filter cell content. + * The default implementation simply renders a space. + * This method may be overridden to customize the rendering of the filter cell (if any). + * @return string the rendering result + */ + protected function renderFilterCellContent() + { + return $this->grid->emptyCell; + } +} diff --git a/framework/yii/widgets/grid/DataColumn.php b/framework/yii/widgets/grid/DataColumn.php new file mode 100644 index 0000000..6035ed2 --- /dev/null +++ b/framework/yii/widgets/grid/DataColumn.php @@ -0,0 +1,95 @@ + + * @since 2.0 + */ +class DataColumn extends Column +{ + public $attribute; + public $value; + public $type; + /** + * @var boolean whether to allow sorting by this column. If true and [[attribute]] is found in + * the sort definition of [[GridView::dataProvider]], then the header cell of this column + * will contain a link that may trigger the sorting when being clicked. + */ + public $enableSorting = true; + /** + * @var string|array|boolean the HTML code representing a filter input (eg a text field, a dropdown list) + * that is used for this data column. This property is effective only when + * {@link CGridView::filter} is set. + * If this property is not set, a text field will be generated as the filter input; + * If this property is an array, a dropdown list will be generated that uses this property value as + * the list options. + * If you don't want a filter for this data column, set this value to false. + * @since 1.1.1 + */ + public $filter; + + + protected function renderHeaderCellContent() + { + if ($this->attribute !== null && $this->header === null) { + $provider = $this->grid->dataProvider; + if ($this->enableSorting && ($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) { + return $sort->link($this->attribute); + } + $items = $provider->getItems(); + if (($item = reset($items)) instanceof Model) { + /** @var Model $item */ + return $item->getAttributeLabel($this->attribute); + } elseif ($provider instanceof ActiveDataProvider) { + if ($provider->query instanceof ActiveQuery) { + /** @var Model $model */ + $model = new $provider->query->modelClass; + return $model->getAttributeLabel($this->attribute); + } + } + return Inflector::camel2words($this->attribute); + } else { + return parent::renderHeaderCellContent(); + } + } + + protected function renderFilterCellContent() + { + if (is_string($this->filter)) { + return $this->filter; + } elseif ($this->filter !== false && $this->grid->filterModel instanceof Model && $this->attribute !== null) { + if (is_array($this->filter)) { + return Html::activeDropDownList($this->grid->filterModel, $this->attribute, $this->filter, array('prompt' => '')); + } else { + return Html::activeTextInput($this->grid->filterModel, $this->attribute); + } + } else { + return parent::renderFilterCellContent(); + } + } + + protected function renderDataCellContent($item, $index) + { + if ($this->value !== null) { + $value = call_user_func($this->value, $item, $index, $this); + } elseif ($this->content === null && $this->attribute !== null) { + $value = ArrayHelper::getValue($item, $this->attribute); + } else { + return parent::renderDataCellContent($item, $index); + } + return $this->grid->formatter->format($value, $this->type); + } +} From c091248e0ddf9461b423fbc2c8297bd11c1d0f63 Mon Sep 17 00:00:00 2001 From: creocoder Date: Thu, 1 Aug 2013 17:19:44 +0400 Subject: [PATCH 06/45] ActiveRecord::getNamespacedClass() call style --- framework/yii/db/ActiveRecord.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/yii/db/ActiveRecord.php b/framework/yii/db/ActiveRecord.php index a047270..5265a81 100644 --- a/framework/yii/db/ActiveRecord.php +++ b/framework/yii/db/ActiveRecord.php @@ -440,7 +440,7 @@ class ActiveRecord extends Model public function hasOne($class, $link) { return new ActiveRelation(array( - 'modelClass' => static::getNamespacedClass($class), + 'modelClass' => $this->getNamespacedClass($class), 'primaryModel' => $this, 'link' => $link, 'multiple' => false, @@ -478,7 +478,7 @@ class ActiveRecord extends Model public function hasMany($class, $link) { return new ActiveRelation(array( - 'modelClass' => static::getNamespacedClass($class), + 'modelClass' => $this->getNamespacedClass($class), 'primaryModel' => $this, 'link' => $link, 'multiple' => true, From d135631f8eef436edaaea40ea5aad62391e258d1 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Thu, 1 Aug 2013 20:06:58 -0400 Subject: [PATCH 07/45] Avoid logging db errors repeatedly. --- framework/yii/db/Command.php | 12 ++++-------- framework/yii/db/Connection.php | 4 +--- framework/yii/debug/panels/LogPanel.php | 2 +- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/framework/yii/db/Command.php b/framework/yii/db/Command.php index a754e34..bf93a2c 100644 --- a/framework/yii/db/Command.php +++ b/framework/yii/db/Command.php @@ -146,9 +146,9 @@ class Command extends \yii\base\Component try { $this->pdoStatement = $this->db->pdo->prepare($sql); } catch (\Exception $e) { - Yii::error($e->getMessage() . "\nFailed to prepare SQL: $sql", __METHOD__); + $message = $e->getMessage() . "\nFailed to prepare SQL: $sql"; $errorInfo = $e instanceof \PDOException ? $e->errorInfo : null; - throw new Exception($e->getMessage(), $errorInfo, (int)$e->getCode(), $e); + throw new Exception($message, $errorInfo, (int)$e->getCode(), $e); } } } @@ -293,10 +293,7 @@ class Command extends \yii\base\Component return $n; } catch (\Exception $e) { Yii::endProfile($token, __METHOD__); - $message = $e->getMessage(); - - Yii::error("$message\nFailed to execute SQL: $rawSql", __METHOD__); - + $message = $e->getMessage() . "\nThe SQL being executed was: $rawSql"; $errorInfo = $e instanceof \PDOException ? $e->errorInfo : null; throw new Exception($message, $errorInfo, (int)$e->getCode(), $e); } @@ -430,8 +427,7 @@ class Command extends \yii\base\Component return $result; } catch (\Exception $e) { Yii::endProfile($token, __METHOD__); - $message = $e->getMessage(); - Yii::error("$message\nCommand::$method() failed: $rawSql", __METHOD__); + $message = $e->getMessage() . "\nThe SQL being executed was: $rawSql"; $errorInfo = $e instanceof \PDOException ? $e->errorInfo : null; throw new Exception($message, $errorInfo, (int)$e->getCode(), $e); } diff --git a/framework/yii/db/Connection.php b/framework/yii/db/Connection.php index 0dd47d8..f27698a 100644 --- a/framework/yii/db/Connection.php +++ b/framework/yii/db/Connection.php @@ -307,9 +307,7 @@ class Connection extends Component Yii::endProfile($token, __METHOD__); } catch (\PDOException $e) { Yii::endProfile($token, __METHOD__); - Yii::error("Failed to open DB connection ({$this->dsn}): " . $e->getMessage(), __METHOD__); - $message = YII_DEBUG ? 'Failed to open DB connection: ' . $e->getMessage() : 'Failed to open DB connection.'; - throw new Exception($message, $e->errorInfo, (int)$e->getCode(), $e); + throw new Exception($e->getMessage(), $e->errorInfo, (int)$e->getCode(), $e); } } } diff --git a/framework/yii/debug/panels/LogPanel.php b/framework/yii/debug/panels/LogPanel.php index b1ad63d..0f56281 100644 --- a/framework/yii/debug/panels/LogPanel.php +++ b/framework/yii/debug/panels/LogPanel.php @@ -55,7 +55,7 @@ EOD; foreach ($this->data['messages'] as $log) { list ($message, $level, $category, $time, $traces) = $log; $time = date('H:i:s.', $time) . sprintf('%03d', (int)(($time - (int)$time) * 1000)); - $message = Html::encode($message); + $message = nl2br(Html::encode($message)); if (!empty($traces)) { $message .= Html::ul($traces, array( 'class' => 'trace', From 71fae803bc26854ed9a308ec56d83c86c08cb7b5 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 2 Aug 2013 17:22:30 +0400 Subject: [PATCH 08/45] fixes #684 --- apps/advanced/frontend/views/emails/passwordResetToken.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/advanced/frontend/views/emails/passwordResetToken.php b/apps/advanced/frontend/views/emails/passwordResetToken.php index 5ab5df1..11aa8e9 100644 --- a/apps/advanced/frontend/views/emails/passwordResetToken.php +++ b/apps/advanced/frontend/views/emails/passwordResetToken.php @@ -6,7 +6,7 @@ use yii\helpers\Html; * @var common\models\User $user; */ -$resetLink = Yii::$app->urlManager->createAbsoluteUrl('site/resetPassword', array('token' => $user->password_reset_token)); +$resetLink = Yii::$app->urlManager->createAbsoluteUrl('site/reset-password', array('token' => $user->password_reset_token)); ?> Hello username)?>, From d1ebf655974093388b4e01551aa8303b7e82414a Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 2 Aug 2013 15:07:23 -0400 Subject: [PATCH 09/45] Fixed the issue that ActiveQuery::one() doesn't bring back related objects when asArray is true. --- framework/yii/db/ActiveQuery.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/framework/yii/db/ActiveQuery.php b/framework/yii/db/ActiveQuery.php index e0c40f7..4d08659 100644 --- a/framework/yii/db/ActiveQuery.php +++ b/framework/yii/db/ActiveQuery.php @@ -124,10 +124,14 @@ class ActiveQuery extends Query { $command = $this->createCommand($db); $row = $command->queryOne(); - if ($row !== false && !$this->asArray) { - /** @var $class ActiveRecord */ - $class = $this->modelClass; - $model = $class::create($row); + if ($row !== false) { + if ($this->asArray) { + $model = $row; + } else { + /** @var $class ActiveRecord */ + $class = $this->modelClass; + $model = $class::create($row); + } if (!empty($this->with)) { $models = array($model); $this->populateRelations($models, $this->with); @@ -135,7 +139,7 @@ class ActiveQuery extends Query } return $model; } else { - return $row === false ? null : $row; + return null; } } From 1398de3f4ad25fd6fb41998f48fe9f4acb729472 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 2 Aug 2013 15:17:37 -0400 Subject: [PATCH 10/45] Renamed DataColumn::type to format. Added GridView::dataColumnClass. --- framework/yii/widgets/GridView.php | 12 +++++++----- framework/yii/widgets/grid/DataColumn.php | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/framework/yii/widgets/GridView.php b/framework/yii/widgets/GridView.php index 98b4884..85b90ea 100644 --- a/framework/yii/widgets/GridView.php +++ b/framework/yii/widgets/GridView.php @@ -26,6 +26,7 @@ class GridView extends ListViewBase const FILTER_POS_FOOTER = 'footer'; const FILTER_POS_BODY = 'body'; + public $dataColumnClass = 'yii\widgets\grid\DataColumn'; public $caption; public $captionOptions = array(); public $tableOptions = array('class' => 'table table-striped table-bordered'); @@ -277,7 +278,7 @@ class GridView extends ListViewBase $column = $this->createDataColumn($column); } else { $column = Yii::createObject(array_merge(array( - 'class' => DataColumn::className(), + 'class' => $this->dataColumnClass, 'grid' => $this, ), $column)); } @@ -300,14 +301,15 @@ class GridView extends ListViewBase */ protected function createDataColumn($text) { - if (!preg_match('/^(\w+)(\s*:\s*(\w+))?$/', $text, $matches)) { - throw new InvalidConfigException('The column must be specified in the format of "Attribute" or "Attribute:Type"'); + if (!preg_match('/^([\w\.]+)(:(\w*))?(:(.*))?$/', $text, $matches)) { + throw new InvalidConfigException('The column must be specified in the format of "Attribute", "Attribute:Format" or "Attribute:Format:Header'); } return Yii::createObject(array( - 'class' => DataColumn::className(), + 'class' => $this->dataColumnClass, 'grid' => $this, 'attribute' => $matches[1], - 'type' => isset($matches[3]) ? $matches[3] : 'text', + 'format' => isset($matches[3]) ? $matches[3] : 'text', + 'header' => isset($matches[5]) ? $matches[5] : null, )); } diff --git a/framework/yii/widgets/grid/DataColumn.php b/framework/yii/widgets/grid/DataColumn.php index 6035ed2..ebe6256 100644 --- a/framework/yii/widgets/grid/DataColumn.php +++ b/framework/yii/widgets/grid/DataColumn.php @@ -22,7 +22,7 @@ class DataColumn extends Column { public $attribute; public $value; - public $type; + public $format; /** * @var boolean whether to allow sorting by this column. If true and [[attribute]] is found in * the sort definition of [[GridView::dataProvider]], then the header cell of this column @@ -90,6 +90,6 @@ class DataColumn extends Column } else { return parent::renderDataCellContent($item, $index); } - return $this->grid->formatter->format($value, $this->type); + return $this->grid->formatter->format($value, $this->format); } } From 5790a00de59d49c6ee88d5f0a5c68c8515109c92 Mon Sep 17 00:00:00 2001 From: yiidevelop Date: Sat, 3 Aug 2013 03:08:32 +0700 Subject: [PATCH 11/45] Add encodeLabels configure Please, review and approval. Thanks --- framework/yii/bootstrap/Nav.php | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/yii/bootstrap/Nav.php b/framework/yii/bootstrap/Nav.php index cea83d8..18ce107 100644 --- a/framework/yii/bootstrap/Nav.php +++ b/framework/yii/bootstrap/Nav.php @@ -136,6 +136,7 @@ class Nav extends Widget if (is_array($items)) { $items = Dropdown::widget(array( 'items' => $items, + 'encodeLabels'=>$this->encodeLabels, 'clientOptions' => false, )); } From f72c451c8631e317f280949294979351eeaff01f Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 2 Aug 2013 16:36:11 -0400 Subject: [PATCH 12/45] Display debug toolbar on error pages. --- framework/yii/base/Application.php | 3 +- framework/yii/base/ErrorHandler.php | 15 ++++++--- framework/yii/views/errorHandler/callStackItem.php | 10 +++--- framework/yii/views/errorHandler/error.php | 27 ++++++++-------- framework/yii/views/errorHandler/exception.php | 37 +++++++++++----------- .../yii/views/errorHandler/previousException.php | 12 +++---- 6 files changed, 56 insertions(+), 48 deletions(-) diff --git a/framework/yii/base/Application.php b/framework/yii/base/Application.php index 0381e16..0b14a8c 100644 --- a/framework/yii/base/Application.php +++ b/framework/yii/base/Application.php @@ -475,6 +475,8 @@ abstract class Application extends Module */ public function handleFatalError() { + unset($this->_memoryReserve); + // load ErrorException manually here because autoloading them will not work // when error occurs while autoloading a class if (!class_exists('\\yii\\base\\Exception', false)) { @@ -487,7 +489,6 @@ abstract class Application extends Module $error = error_get_last(); if (ErrorException::isFatalError($error)) { - unset($this->_memoryReserve); $exception = new ErrorException($error['message'], $error['type'], $error['type'], $error['file'], $error['line']); // use error_log because it's too late to use Yii log error_log($exception); diff --git a/framework/yii/base/ErrorHandler.php b/framework/yii/base/ErrorHandler.php index 39c87b0..99428fc 100644 --- a/framework/yii/base/ErrorHandler.php +++ b/framework/yii/base/ErrorHandler.php @@ -192,11 +192,16 @@ class ErrorHandler extends Component */ public function renderFile($_file_, $_params_) { - ob_start(); - ob_implicit_flush(false); - extract($_params_, EXTR_OVERWRITE); - require(Yii::getAlias($_file_)); - return ob_get_clean(); + $_params_['handler'] = $this; + if ($this->exception instanceof ErrorException) { + ob_start(); + ob_implicit_flush(false); + extract($_params_, EXTR_OVERWRITE); + require(Yii::getAlias($_file_)); + return ob_get_clean(); + } else { + return Yii::$app->getView()->renderFile($_file_, $_params_, $this); + } } /** diff --git a/framework/yii/views/errorHandler/callStackItem.php b/framework/yii/views/errorHandler/callStackItem.php index 2cbced0..20ad398 100644 --- a/framework/yii/views/errorHandler/callStackItem.php +++ b/framework/yii/views/errorHandler/callStackItem.php @@ -8,19 +8,19 @@ * @var string[] $lines * @var integer $begin * @var integer $end - * @var \yii\base\ErrorHandler $this + * @var \yii\base\ErrorHandler $handler */ ?> -
  • . - htmlEncode($file); ?> + htmlEncode($file); ?> - addTypeLinks($class) . '::'; ?>addTypeLinks($method . '()'); ?> + addTypeLinks($class) . '::'; ?>addTypeLinks($method . '()'); ?> @@ -36,7 +36,7 @@
    htmlEncode($lines[$i]);
    +						echo (trim($lines[$i]) == '') ? " \n" : $handler->htmlEncode($lines[$i]);
     					}
     				?>
    diff --git a/framework/yii/views/errorHandler/error.php b/framework/yii/views/errorHandler/error.php index 4765bdd..46ba47f 100644 --- a/framework/yii/views/errorHandler/error.php +++ b/framework/yii/views/errorHandler/error.php @@ -1,9 +1,9 @@ htmlEncode($exception instanceof \yii\base\Exception ? $exception->getName() : get_class($exception)); +$title = $handler->htmlEncode($exception instanceof \yii\base\Exception ? $exception->getName() : get_class($exception)); ?> @@ -50,16 +50,17 @@ $title = $this->htmlEncode($exception instanceof \yii\base\Exception ? $exceptio -

    -

    htmlEncode($exception->getMessage()))?>

    -

    - The above error occurred while the Web server was processing your request. -

    -

    - Please contact us if you think this is a server error. Thank you. -

    -
    - -
    +

    +

    htmlEncode($exception->getMessage()))?>

    +

    + The above error occurred while the Web server was processing your request. +

    +

    + Please contact us if you think this is a server error. Thank you. +

    +
    + +
    + endBody(); // to allow injecting code into body (mostly by Yii Debug Toolbar) ?> diff --git a/framework/yii/views/errorHandler/exception.php b/framework/yii/views/errorHandler/exception.php index 8c6612a..7c3d277 100644 --- a/framework/yii/views/errorHandler/exception.php +++ b/framework/yii/views/errorHandler/exception.php @@ -1,7 +1,7 @@ @@ -12,11 +12,11 @@ <?php if ($exception instanceof \yii\web\HttpException) { - echo (int) $exception->statusCode . ' ' . $this->htmlEncode($exception->getName()); + echo (int) $exception->statusCode . ' ' . $handler->htmlEncode($exception->getName()); } elseif ($exception instanceof \yii\base\Exception) { - echo $this->htmlEncode($exception->getName() . ' – ' . get_class($exception)); + echo $handler->htmlEncode($exception->getName() . ' – ' . get_class($exception)); } else { - echo $this->htmlEncode(get_class($exception)); + echo $handler->htmlEncode(get_class($exception)); } ?> @@ -353,32 +353,32 @@ pre .diff .change{ Gears

    - htmlEncode($exception->getName()); ?> - – addTypeLinks(get_class($exception)); ?> + htmlEncode($exception->getName()); ?> + – addTypeLinks(get_class($exception)); ?>

    Attention

    ' . $this->createHttpStatusLink($exception->statusCode, $this->htmlEncode($exception->getName())) . ''; - echo ' – ' . $this->addTypeLinks(get_class($exception)); + echo '' . $handler->createHttpStatusLink($exception->statusCode, $handler->htmlEncode($exception->getName())) . ''; + echo ' – ' . $handler->addTypeLinks(get_class($exception)); } elseif ($exception instanceof \yii\base\Exception) { - echo '' . $this->htmlEncode($exception->getName()) . ''; - echo ' – ' . $this->addTypeLinks(get_class($exception)); + echo '' . $handler->htmlEncode($exception->getName()) . ''; + echo ' – ' . $handler->addTypeLinks(get_class($exception)); } else { - echo '' . $this->htmlEncode(get_class($exception)) . ''; + echo '' . $handler->htmlEncode(get_class($exception)) . ''; } ?>

    -

    htmlEncode($exception->getMessage()); ?>

    - renderPreviousExceptions($exception); ?> +

    htmlEncode($exception->getMessage()); ?>

    + renderPreviousExceptions($exception); ?>
      - renderCallStackItem($exception->getFile(), $exception->getLine(), null, null, 1); ?> + renderCallStackItem($exception->getFile(), $exception->getLine(), null, null, 1); ?> getTrace(), $length = count($trace); $i < $length; ++$i): ?> - renderCallStackItem(@$trace[$i]['file'] ?: null, @$trace[$i]['line'] ?: null, + renderCallStackItem(@$trace[$i]['file'] ?: null, @$trace[$i]['line'] ?: null, @$trace[$i]['class'] ?: null, @$trace[$i]['function'] ?: null, $i + 1); ?>
    @@ -386,15 +386,15 @@ pre .diff .change{
    - renderRequest(); ?> + renderRequest(); ?>
    + endBody(); // to allow injecting code into body (mostly by Yii Debug Toolbar) ?> diff --git a/framework/yii/views/errorHandler/previousException.php b/framework/yii/views/errorHandler/previousException.php index d56f6dd..e6dcf87 100644 --- a/framework/yii/views/errorHandler/previousException.php +++ b/framework/yii/views/errorHandler/previousException.php @@ -1,7 +1,7 @@ From 478560fdd1a9ed34f0335ccdd77c8bd8744c6448 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 3 Aug 2013 01:16:11 +0400 Subject: [PATCH 13/45] requirements: fixed intl version checking --- framework/yii/requirements/requirements.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/yii/requirements/requirements.php b/framework/yii/requirements/requirements.php index 670544d..005a205 100644 --- a/framework/yii/requirements/requirements.php +++ b/framework/yii/requirements/requirements.php @@ -41,7 +41,7 @@ return array( array( 'name' => 'Intl extension', 'mandatory' => false, - 'condition' => $this->checkPhpExtensionVersion('intl', '1.0.2'), + 'condition' => $this->checkPhpExtensionVersion('intl', '1.0.2', '>='), 'by' => 'Internationalization support', 'memo' => 'PHP Intl extension 1.0.2 or higher is required when you want to use IDN-feature of EmailValidator or UrlValidator or the yii\i18n\Formatter class.' ), From 3a2215b833a5dd911973aee1997da5489dfa88a0 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 3 Aug 2013 01:19:26 +0400 Subject: [PATCH 14/45] fixed length constraints check to always result in correct range --- framework/yii/web/CaptchaAction.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/yii/web/CaptchaAction.php b/framework/yii/web/CaptchaAction.php index 98599d9..fef44fd 100644 --- a/framework/yii/web/CaptchaAction.php +++ b/framework/yii/web/CaptchaAction.php @@ -189,15 +189,15 @@ class CaptchaAction extends Action */ protected function generateVerifyCode() { + if ($this->minLength > $this->maxLength) { + $this->maxLength = $this->minLength; + } if ($this->minLength < 3) { $this->minLength = 3; } if ($this->maxLength > 20) { $this->maxLength = 20; } - if ($this->minLength > $this->maxLength) { - $this->maxLength = $this->minLength; - } $length = mt_rand($this->minLength, $this->maxLength); $letters = 'bcdfghjklmnpqrstvwxyz'; From 0cde54bc3c5ed42dbc7427a73ee5c2cb998a434b Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 3 Aug 2013 01:23:17 +0400 Subject: [PATCH 15/45] added note about routes for camelCased controllers and actions --- docs/guide/controller.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/guide/controller.md b/docs/guide/controller.md index c550b42..29918f0 100644 --- a/docs/guide/controller.md +++ b/docs/guide/controller.md @@ -50,6 +50,9 @@ If controller is located inside a module its action internal route will be `modu In case module, controller or action specified isn't found Yii will return "not found" page and HTTP status code 404. +> Note: If controller name or action name contains camelCased words, internal route will use dashes i.e. for +`DateTimeController::actionFastForward` route will be `date-time/fast-forward`. + ### Defaults If user isn't specifying any route i.e. using URL like `http://example.com/`, Yii assumes that default route should be From 4ac501f4924b4b00fdd5549dd6909e5a8f793cdd Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 2 Aug 2013 17:25:03 -0400 Subject: [PATCH 16/45] Removed placeholders. --- framework/yii/views/errorHandler/error.php | 2 ++ framework/yii/views/errorHandler/exception.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/framework/yii/views/errorHandler/error.php b/framework/yii/views/errorHandler/error.php index 46ba47f..c9afaf5 100644 --- a/framework/yii/views/errorHandler/error.php +++ b/framework/yii/views/errorHandler/error.php @@ -5,6 +5,7 @@ */ $title = $handler->htmlEncode($exception instanceof \yii\base\Exception ? $exception->getName() : get_class($exception)); ?> +beginPage(); ?> @@ -64,3 +65,4 @@ $title = $handler->htmlEncode($exception instanceof \yii\base\Exception ? $excep endBody(); // to allow injecting code into body (mostly by Yii Debug Toolbar) ?> +endPage(); ?> diff --git a/framework/yii/views/errorHandler/exception.php b/framework/yii/views/errorHandler/exception.php index 7c3d277..6482fae 100644 --- a/framework/yii/views/errorHandler/exception.php +++ b/framework/yii/views/errorHandler/exception.php @@ -4,6 +4,7 @@ * @var \yii\base\ErrorHandler $handler */ ?> +beginPage(); ?> @@ -488,3 +489,4 @@ window.onload = function() { +endPage(); ?> From 9f4ccb6243e536ca22cd401ff8cb80bb1312f281 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 2 Aug 2013 22:07:26 -0400 Subject: [PATCH 17/45] Added status code display to debugger toolbar. --- framework/yii/debug/panels/ProfilingPanel.php | 4 ++-- framework/yii/debug/panels/RequestPanel.php | 17 +++++++++++++++++ framework/yii/web/Response.php | 1 - 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/framework/yii/debug/panels/ProfilingPanel.php b/framework/yii/debug/panels/ProfilingPanel.php index 5bd32ee..b614611 100644 --- a/framework/yii/debug/panels/ProfilingPanel.php +++ b/framework/yii/debug/panels/ProfilingPanel.php @@ -33,10 +33,10 @@ class ProfilingPanel extends Panel return << - Time: $time + Time: $time
    EOD; } diff --git a/framework/yii/debug/panels/RequestPanel.php b/framework/yii/debug/panels/RequestPanel.php index e709de6..e655f2d 100644 --- a/framework/yii/debug/panels/RequestPanel.php +++ b/framework/yii/debug/panels/RequestPanel.php @@ -12,6 +12,7 @@ use yii\base\InlineAction; use yii\bootstrap\Tabs; use yii\debug\Panel; use yii\helpers\Html; +use yii\web\Response; /** * Debugger panel that collects and displays request data. @@ -29,9 +30,24 @@ class RequestPanel extends Panel public function getSummary() { $url = $this->getUrl(); + $statusCode = $this->data['statusCode']; + if ($statusCode === null) { + $statusCode = 200; + } + if ($statusCode >= 200 && $statusCode < 300) { + $class = 'label-success'; + } elseif ($statusCode >= 100 && $statusCode < 200) { + $class = 'label-info'; + } else { + $class = 'label-important'; + } + $statusText = Html::encode(isset(Response::$httpStatuses[$statusCode]) ? Response::$httpStatuses[$statusCode] : ''); return << + $statusCode + + EOD; @@ -113,6 +129,7 @@ EOD; $session = Yii::$app->getComponent('session', false); return array( 'flashes' => $session ? $session->getAllFlashes() : array(), + 'statusCode' => Yii::$app->getResponse()->getStatusCode(), 'requestHeaders' => $requestHeaders, 'responseHeaders' => $responseHeaders, 'route' => Yii::$app->requestedAction ? Yii::$app->requestedAction->getUniqueId() : Yii::$app->requestedRoute, diff --git a/framework/yii/web/Response.php b/framework/yii/web/Response.php index 5371122..6bb888c 100644 --- a/framework/yii/web/Response.php +++ b/framework/yii/web/Response.php @@ -258,7 +258,6 @@ class Response extends \yii\base\Response $this->sendHeaders(); $this->sendContent(); $this->trigger(self::EVENT_AFTER_SEND, new ResponseEvent($this)); - $this->clear(); } /** From f829b9478b3c6b59daff0f058ca8549764d1ae8f Mon Sep 17 00:00:00 2001 From: Luciano Baraglia Date: Sat, 3 Aug 2013 02:05:49 -0300 Subject: [PATCH 18/45] Minor doc and messages fixes [skip ci] --- framework/yii/widgets/DetailView.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/yii/widgets/DetailView.php b/framework/yii/widgets/DetailView.php index 229cdec..c3bf864 100644 --- a/framework/yii/widgets/DetailView.php +++ b/framework/yii/widgets/DetailView.php @@ -21,7 +21,7 @@ use yii\helpers\Inflector; * DetailView displays the detail of a single data [[model]]. * * DetailView is best used for displaying a model in a regular format (e.g. each model attribute - * is displayed as a row in a table.) The model can be either an instance of [[Model]] or + * is displayed as a row in a table.) The model can be either an instance of [[Model]] * or an associative array. * * DetailView uses the [[attributes]] property to determines which model attributes @@ -105,7 +105,7 @@ class DetailView extends Widget public function init() { if ($this->model === null) { - throw new InvalidConfigException('Please specify the "data" property.'); + throw new InvalidConfigException('Please specify the "model" property.'); } if ($this->formatter == null) { $this->formatter = Yii::$app->getFormatter(); @@ -166,7 +166,7 @@ class DetailView extends Widget } elseif (is_array($this->model)) { $this->attributes = array_keys($this->model); } else { - throw new InvalidConfigException('The "data" property must be either an array or an object.'); + throw new InvalidConfigException('The "model" property must be either an array or an object.'); } sort($this->attributes); } From 8760407cc9595503a77fad23d77e96622751d806 Mon Sep 17 00:00:00 2001 From: Luciano Baraglia Date: Sat, 3 Aug 2013 02:13:22 -0300 Subject: [PATCH 19/45] Some doc code cleanup [skip ci] --- framework/yii/bootstrap/Carousel.php | 2 +- framework/yii/bootstrap/Collapse.php | 6 +++--- framework/yii/bootstrap/Nav.php | 2 +- framework/yii/bootstrap/NavBar.php | 2 +- framework/yii/bootstrap/Progress.php | 2 +- framework/yii/bootstrap/Tabs.php | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/framework/yii/bootstrap/Carousel.php b/framework/yii/bootstrap/Carousel.php index c2c68a7..ec9a0c9 100644 --- a/framework/yii/bootstrap/Carousel.php +++ b/framework/yii/bootstrap/Carousel.php @@ -55,7 +55,7 @@ class Carousel extends Widget * // required, slide content (HTML), such as an image tag * 'content' => '', * // optional, the caption (HTML) of the slide - * 'caption'=> '

    This is title

    This is the caption text

    ', + * 'caption' => '

    This is title

    This is the caption text

    ', * // optional the HTML attributes of the slide container * 'options' => array(), * ) diff --git a/framework/yii/bootstrap/Collapse.php b/framework/yii/bootstrap/Collapse.php index 8aed0b1..77fdde7 100644 --- a/framework/yii/bootstrap/Collapse.php +++ b/framework/yii/bootstrap/Collapse.php @@ -23,7 +23,7 @@ use yii\helpers\Html; * 'Collapsible Group Item #1' => array( * 'content' => 'Anim pariatur cliche...', * // open its content by default - * 'contentOptions' => array('class'=>'in') + * 'contentOptions' => array('class' => 'in') * ), * // another group item * 'Collapsible Group Item #2' => array( @@ -51,9 +51,9 @@ class Collapse extends Widget * // required, the content (HTML) of the group * 'content' => 'Anim pariatur cliche...', * // optional the HTML attributes of the content group - * 'contentOptions'=> array(), + * 'contentOptions' => array(), * // optional the HTML attributes of the group - * 'options'=> array(), + * 'options' => array(), * ) * ``` */ diff --git a/framework/yii/bootstrap/Nav.php b/framework/yii/bootstrap/Nav.php index 18ce107..5b5d40b 100644 --- a/framework/yii/bootstrap/Nav.php +++ b/framework/yii/bootstrap/Nav.php @@ -136,7 +136,7 @@ class Nav extends Widget if (is_array($items)) { $items = Dropdown::widget(array( 'items' => $items, - 'encodeLabels'=>$this->encodeLabels, + 'encodeLabels' => $this->encodeLabels, 'clientOptions' => false, )); } diff --git a/framework/yii/bootstrap/NavBar.php b/framework/yii/bootstrap/NavBar.php index f801df5..52804c4 100644 --- a/framework/yii/bootstrap/NavBar.php +++ b/framework/yii/bootstrap/NavBar.php @@ -87,7 +87,7 @@ class NavBar extends Widget * // optional, the menu item class type of the widget to render. Defaults to "Nav" widget. * 'class' => 'Menu item class type', * // required, the configuration options of the widget. - * 'options'=> array(...), + * 'options' => array(...), * ), * // optionally, you can pass a string * '