[gridview] -- Column源码

来源:互联网 发布:数据库物理设计图visio 编辑:程序博客网 时间:2024/06/14 08:21
<?php/** * @link http://www.yiiframework.com/ * @copyright Copyright (c) 2008 Yii Software LLC * @license http://www.yiiframework.com/license/ */namespace yii\grid;use Closure;use yii\base\Object;use yii\helpers\Html;/** * Column is the base class of all [[GridView]] column classes. * * @author Qiang Xue <qiang.xue@gmail.com> * @since 2.0 */class Column extends Object{    /**     * @var GridView the grid view object that owns this column.     * @var GridView 拥有这一列的网格视图object     */    public $grid;    /**     * @var string the header cell content. Note that it will not be HTML-encoded.     * @var string 标题单元格内容。请注意,它不会HTML-encoded。     */    public $header;    /**     * @var string the footer cell content. Note that it will not be HTML-encoded.     * @var string 底部单元格内容, 请注意, 他不会html-encoded     */    public $footer;    /**     * @var callable This is a callable that will be used to generate the content of each cell.     * The signature of the function should be the following: `function ($model, $key, $index, $column)`.     * Where `$model`, `$key`, and `$index` refer to the model, key and index of the row currently being rendered     * and `$column` is a reference to the [[Column]] object     *     * @var callable 这个调用将用于生成每个单元格的内容。     * 函数的签名应该如下:`function ($model, $key, $index, $column)`     */    public $content;    /**     * @var boolean whether this column is visible. Defaults to true.     * @var boolean 这一列是否可见。默认值为true。     */    public $visible = true;    /**     * @var array the HTML attributes for the column group tag.     * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.     * @var array HTML属性列组标签。     * @see \yii\helpers\Html::renderTagAttributes() 属性是如何被渲染的细节     */    public $options = [];    /**     * @var array the HTML attributes for the header cell tag.     * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.     * @var array HTML头部单元标签     * @see \yii\helpers\Html::renderTagAttributes() 属性是如何被渲染的细节     */    public $headerOptions = [];    /**     * @var array|\Closure the HTML attributes for the data cell tag. This can either be an array of     * attributes or an anonymous function ([[Closure]]) that returns such an array.     * The signature of the function should be the following: `function ($model, $key, $index, $column)`.     * Where `$model`, `$key`, and `$index` refer to the model, key and index of the row currently being rendered     * and `$column` is a reference to the [[Column]] object.     * A function may be used to assign different attributes to different rows based on the data in that row.     *     * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.     * @var array|\Closure HTML属性数据单元标签。这可以是一个数组     * 属性或一个匿名函数function ([[Closure]]) 返回一个数组     * 函数的签名应该是以下: `function ($model, $key, $index, $column)`.     * Where `$model`, `$key`, and `$index` refer to the model, key and index of the row currently being rendered     * [[column]]是一个引用对象     * 一个函数可以用来将不同属性分配给不同的行基于这一行中的数据。     *  @see \yii\helpers\Html::renderTagAttributes() 属性是如何被渲染的细节     */    public $contentOptions = [];    /**     * @var array the HTML attributes for the footer cell tag.     * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.     */    public $footerOptions = [];    /**     * @var array the HTML attributes for the filter cell tag.     * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.     */    public $filterOptions = [];    /**     * 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 $model the data model being rendered     * @param mixed $key the key associated with the data model     * @param integer $index the zero-based index of the data item among the item array returned by [[GridView::dataProvider]].     * @return string the rendering result     */    public function renderDataCell($model, $key, $index)    {        if ($this->contentOptions instanceof Closure) {            $options = call_user_func($this->contentOptions, $model, $key, $index, $this);        } else {            $options = $this->contentOptions;        }        return Html::tag('td', $this->renderDataCellContent($model, $key, $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 [[header]].     * This method may be overridden to customize the rendering of the header cell.     * 这种方法可能会覆盖自定义标题单元格的渲染。     * @return string the rendering result     * @return string 返回渲染结果     */    protected function renderHeaderCellContent()    {        return trim($this->header) !== '' ? $this->header : $this->grid->emptyCell;    }    /**     * Renders the footer cell content.     * The default implementation simply renders [[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 $model the data model     * @param mixed $key the key associated with the data model     * @param integer $index the zero-based index of the data model among the models array returned by [[GridView::dataProvider]].     * @return string the rendering result     */    protected function renderDataCellContent($model, $key, $index)    {        if ($this->content !== null) {            return call_user_func($this->content, $model, $key, $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;    }}

0 0