類別 yii\grid\SerialColumn
繼承 | yii\grid\SerialColumn » yii\grid\Column » yii\base\BaseObject |
---|---|
實作 | yii\base\Configurable |
自版本起可用 | 2.0 |
原始碼 | https://github.com/yiisoft/yii2/blob/master/framework/grid/SerialColumn.php |
SerialColumn 顯示一欄從 1 開始的列號。
若要將 SerialColumn 新增至 yii\grid\GridView,請將其新增至 columns 配置,如下所示
'columns' => [
// ...
[
'class' => 'yii\grid\SerialColumn',
// you may configure additional properties here
],
]
如需更多關於 SerialColumn 的詳細資訊和使用方式,請參閱關於資料小部件的指南文章。
公共屬性
屬性 | 類型 | 描述 | 定義於 |
---|---|---|---|
$content | 可呼叫 (callable) | 這是一個可呼叫的函數,將用於生成每個儲存格的內容。 | yii\grid\Column |
$contentOptions | 陣列 (array)|閉包 (Closure) | 資料儲存格標籤的 HTML 屬性。 | yii\grid\Column |
$filterOptions | 陣列 (array) | 篩選儲存格標籤的 HTML 屬性。 | yii\grid\Column |
$footer | 字串 (string) | 頁腳儲存格內容。 | yii\grid\Column |
$footerOptions | 陣列 (array) | 頁腳儲存格標籤的 HTML 屬性。 | yii\grid\Column |
$grid | yii\grid\GridView | 擁有此欄的網格視圖物件。 | yii\grid\Column |
$header | 字串 (string)|null | 標題儲存格內容。 | yii\grid\SerialColumn |
$headerOptions | 陣列 (array) | 標題儲存格標籤的 HTML 屬性。 | yii\grid\Column |
$options | 陣列 (array) | 欄組標籤的 HTML 屬性。 | yii\grid\Column |
$visible | 布林值 (boolean) | 此欄是否可見。 | yii\grid\Column |
公共方法
方法 | 描述 | 定義於 |
---|---|---|
__call() | 呼叫未定義為類別方法的具名方法。 | yii\base\BaseObject |
__construct() | 建構子。 | yii\base\BaseObject |
__get() | 傳回物件屬性的值。 | yii\base\BaseObject |
__isset() | 檢查屬性是否已設定,即已定義且非 null。 | yii\base\BaseObject |
__set() | 設定物件屬性的值。 | yii\base\BaseObject |
__unset() | 將物件屬性設定為 null。 | yii\base\BaseObject |
canGetProperty() | 傳回一個值,指示是否可以讀取屬性。 | yii\base\BaseObject |
canSetProperty() | 傳回一個值,指示是否可以設定屬性。 | yii\base\BaseObject |
className() | 傳回此類別的完整限定名稱。 | yii\base\BaseObject |
hasMethod() | 傳回一個值,指示是否已定義方法。 | yii\base\BaseObject |
hasProperty() | 傳回一個值,指示是否已定義屬性。 | yii\base\BaseObject |
init() | 初始化物件。 | yii\base\BaseObject |
renderDataCell() | 渲染資料儲存格。 | yii\grid\Column |
renderFilterCell() | 渲染篩選儲存格。 | yii\grid\Column |
renderFooterCell() | 渲染頁腳儲存格。 | yii\grid\Column |
renderHeaderCell() | 渲染標題儲存格。 | yii\grid\Column |
保護方法
方法 | 描述 | 定義於 |
---|---|---|
getHeaderCellLabel() | 傳回標題儲存格標籤。 | yii\grid\Column |
renderDataCellContent() | 渲染資料儲存格內容。 | yii\grid\SerialColumn |
renderFilterCellContent() | 渲染篩選儲存格內容。 | yii\grid\Column |
renderFooterCellContent() | 渲染頁腳儲存格內容。 | yii\grid\Column |
renderHeaderCellContent() | 渲染標題儲存格內容。 | yii\grid\Column |
屬性詳細資訊
方法詳細資訊
public mixed __call ( $name, $params ) | ||
$name | 字串 (string) |
方法名稱 |
$params | 陣列 (array) |
方法參數 |
return | mixed |
方法傳回值 |
---|---|---|
throws | yii\base\UnknownMethodException |
當呼叫未知方法時 |
public function __call($name, $params)
{
throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()");
}
定義於: yii\base\BaseObject::__construct()
建構子。
預設實作執行兩件事
- 使用給定的組態
$config
初始化物件。 - 呼叫 init()。
如果子類別中覆寫了此方法,建議
- 建構子的最後一個參數是一個組態陣列,例如此處的
$config
。 - 在建構子的結尾呼叫父類別實作。
public void __construct ( $config = [] ) | ||
$config | 陣列 (array) |
將用於初始化物件屬性的名稱-值對 |
public function __construct($config = [])
{
if (!empty($config)) {
Yii::configure($this, $config);
}
$this->init();
}
定義於: yii\base\BaseObject::__get()
傳回物件屬性的值。
請勿直接呼叫此方法,因為它是一個 PHP 魔術方法,當執行 $value = $object->property;
時,會被隱式呼叫。
另請參閱 __set()。
public mixed __get ( $name ) | ||
$name | 字串 (string) |
屬性名稱 |
return | mixed |
屬性值 |
---|---|---|
throws | yii\base\UnknownPropertyException |
如果屬性未定義 |
throws | yii\base\InvalidCallException |
如果屬性為唯寫 |
public function __get($name)
{
$getter = 'get' . $name;
if (method_exists($this, $getter)) {
return $this->$getter();
} elseif (method_exists($this, 'set' . $name)) {
throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name);
}
throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name);
}
定義於: yii\base\BaseObject::__isset()
檢查屬性是否已設定,即已定義且非 null。
請勿直接呼叫此方法,因為它是一個 PHP 魔術方法,當執行 isset($object->property)
時,會被隱式呼叫。
請注意,如果屬性未定義,將傳回 false。
public 布林值 (boolean) __isset ( $name ) | ||
$name | 字串 (string) |
屬性名稱或事件名稱 |
return | 布林值 (boolean) |
具名屬性是否已設定(非 null)。 |
---|
public function __isset($name)
{
$getter = 'get' . $name;
if (method_exists($this, $getter)) {
return $this->$getter() !== null;
}
return false;
}
定義於: yii\base\BaseObject::__set()
設定物件屬性的值。
請勿直接呼叫此方法,因為它是一個 PHP 魔術方法,當執行 $object->property = $value;
時,會被隱式呼叫。
另請參閱 __get()。
public void __set ( $name, $value ) | ||
$name | 字串 (string) |
屬性名稱或事件名稱 |
$value | mixed |
屬性值 |
throws | yii\base\UnknownPropertyException |
如果屬性未定義 |
---|---|---|
throws | yii\base\InvalidCallException |
如果屬性為唯讀 |
public function __set($name, $value)
{
$setter = 'set' . $name;
if (method_exists($this, $setter)) {
$this->$setter($value);
} elseif (method_exists($this, 'get' . $name)) {
throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
} else {
throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
}
}
定義於: yii\base\BaseObject::__unset()
將物件屬性設定為 null。
請勿直接呼叫此方法,因為它是一個 PHP 魔術方法,當執行 unset($object->property)
時,會被隱式呼叫。
請注意,如果屬性未定義,此方法將不會執行任何操作。 如果屬性為唯讀,則會拋出例外。
public void __unset ( $name ) | ||
$name | 字串 (string) |
屬性名稱 |
throws | yii\base\InvalidCallException |
如果屬性為唯讀。 |
---|
public function __unset($name)
{
$setter = 'set' . $name;
if (method_exists($this, $setter)) {
$this->$setter(null);
} elseif (method_exists($this, 'get' . $name)) {
throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . '::' . $name);
}
}
定義於: yii\base\BaseObject::canGetProperty()
傳回一個值,指示是否可以讀取屬性。
如果符合以下條件,屬性是可讀的:
- 類別具有與指定名稱相關聯的 getter 方法(在這種情況下,屬性名稱不區分大小寫);
- 類別具有帶有指定名稱的成員變數(當
$checkVars
為 true 時);
另請參閱 canSetProperty()。
public 布林值 (boolean) canGetProperty ( $name, $checkVars = true ) | ||
$name | 字串 (string) |
屬性名稱 |
$checkVars | 布林值 (boolean) |
是否將成員變數視為屬性 |
return | 布林值 (boolean) |
屬性是否可讀 |
---|
public function canGetProperty($name, $checkVars = true)
{
return method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name);
}
定義於: yii\base\BaseObject::canSetProperty()
傳回一個值,指示是否可以設定屬性。
如果符合以下條件,屬性是可寫入的:
- 類別具有與指定名稱相關聯的 setter 方法(在這種情況下,屬性名稱不區分大小寫);
- 類別具有帶有指定名稱的成員變數(當
$checkVars
為 true 時);
另請參閱 canGetProperty()。
public 布林值 (boolean) canSetProperty ( $name, $checkVars = true ) | ||
$name | 字串 (string) |
屬性名稱 |
$checkVars | 布林值 (boolean) |
是否將成員變數視為屬性 |
return | 布林值 (boolean) |
屬性是否可寫入 |
---|
public function canSetProperty($name, $checkVars = true)
{
return method_exists($this, 'set' . $name) || $checkVars && property_exists($this, $name);
}
::class
。
定義於: yii\base\BaseObject::className()
傳回此類別的完整限定名稱。
public static 字串 (string) className ( ) | ||
return | 字串 (string) |
此類別的完整限定名稱。 |
---|
public static function className()
{
return get_called_class();
}
protected 字串 (string) getHeaderCellLabel ( ) | ||
return | 字串 (string) |
標籤 |
---|
protected function getHeaderCellLabel()
{
return $this->grid->emptyCell;
}
定義於: yii\base\BaseObject::hasMethod()
傳回一個值,指示是否已定義方法。
預設實作是對 php 函數 method_exists()
的呼叫。 當您實作 php 魔術方法 __call()
時,您可以覆寫此方法。
public 布林值 (boolean) hasMethod ( $name ) | ||
$name | 字串 (string) |
方法名稱 |
return | 布林值 (boolean) |
方法是否已定義 |
---|
public function hasMethod($name)
{
return method_exists($this, $name);
}
定義於: yii\base\BaseObject::hasProperty()
傳回一個值,指示是否已定義屬性。
如果符合以下條件,則定義了屬性:
- 類別具有與指定名稱相關聯的 getter 或 setter 方法(在這種情況下,屬性名稱不區分大小寫);
- 類別具有帶有指定名稱的成員變數(當
$checkVars
為 true 時);
另請參閱
public 布林值 (boolean) hasProperty ( $name, $checkVars = true ) | ||
$name | 字串 (string) |
屬性名稱 |
$checkVars | 布林值 (boolean) |
是否將成員變數視為屬性 |
return | 布林值 (boolean) |
屬性是否已定義 |
---|
public function hasProperty($name, $checkVars = true)
{
return $this->canGetProperty($name, $checkVars) || $this->canSetProperty($name, false);
}
public void init ( ) |
public function init()
{
}
定義於: yii\grid\Column::renderDataCell()
渲染資料儲存格。
public 字串 (string) renderDataCell ( $model, $key, $index ) | ||
$model | mixed |
正在渲染的資料模型 |
$key | mixed |
與資料模型相關聯的鍵 |
$index | 整數 (integer) |
資料項目在 yii\grid\GridView::$dataProvider 傳回的項目陣列中的從零開始的索引。 |
return | 字串 (string) |
渲染結果 |
---|
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);
}
渲染資料儲存格內容。
protected 字串 (string) renderDataCellContent ( $model, $key, $index ) | ||
$model | mixed |
資料模型 |
$key | mixed |
與資料模型相關聯的鍵 |
$index | 整數 (integer) |
資料模型在 yii\grid\GridView::$dataProvider 傳回的模型陣列中的從零開始的索引。 |
return | 字串 (string) |
渲染結果 |
---|
protected function renderDataCellContent($model, $key, $index)
{
$pagination = $this->grid->dataProvider->getPagination();
if ($pagination !== false) {
return $pagination->getOffset() + $index + 1;
}
return $index + 1;
}
定義於: yii\grid\Column::renderFilterCell()
渲染篩選儲存格。
public void renderFilterCell ( ) |
public function renderFilterCell()
{
return Html::tag('td', $this->renderFilterCellContent(), $this->filterOptions);
}
protected 字串 (string) renderFilterCellContent ( ) | ||
return | 字串 (string) |
渲染結果 |
---|
protected function renderFilterCellContent()
{
return $this->grid->emptyCell;
}
定義於: yii\grid\Column::renderHeaderCell()
渲染標題儲存格。
public void renderHeaderCell ( ) |
public function renderHeaderCell()
{
return Html::tag('th', $this->renderHeaderCellContent(), $this->headerOptions);
}
protected 字串 (string) renderHeaderCellContent ( ) | ||
return | 字串 (string) |
渲染結果 |
---|
protected function renderHeaderCellContent()
{
return $this->header !== null && trim($this->header) !== '' ? $this->header : $this->getHeaderCellLabel();
}
註冊 或 登入 以發表評論。