亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Verzeichnis suchen
歡迎 目錄 快速參考圖 基本信息 服務(wù)器要求 許可協(xié)議 變更記錄 關(guān)于CodeIgniter 安裝 下載 CodeIgniter 安裝指導(dǎo) 從老版本升級(jí) 疑難解答 介紹 開(kāi)始 CodeIgniter 是什么? CodeIgniter 速記表 支持特性 應(yīng)用程序流程圖 模型-視圖-控制器 架構(gòu)目標(biāo) 教程 內(nèi)容提要 加載靜態(tài)內(nèi)容 創(chuàng)建新聞條目 讀取新聞條目 結(jié)束語(yǔ) 常規(guī)主題 CodeIgniter URL 控制器 保留字 視圖 模型 輔助函數(shù) 使用 CodeIgniter 類庫(kù) 創(chuàng)建你自己的類庫(kù) 使用 CodeIgniter 適配器 創(chuàng)建適配器 創(chuàng)建核心系統(tǒng)類 鉤子 - 擴(kuò)展框架的核心 自動(dòng)裝載資源 公共函數(shù) URI 路由 錯(cuò)誤處理 緩存 調(diào)試應(yīng)用程序 以CLI方式運(yùn)行 管理應(yīng)用程序 處理多環(huán)境 PHP替代語(yǔ)法 安全 開(kāi)發(fā)規(guī)范 類庫(kù)參考 基準(zhǔn)測(cè)試類 日歷類 購(gòu)物車類 配置類 Email 類 加密類 文件上傳類 表單驗(yàn)證詳解 FTP 類 圖像處理類 輸入類 Javascript 類 語(yǔ)言類 裝載類 遷移類 輸出類 分頁(yè)類 模板解析器類 安全類 Session 類 HTML 表格類 引用通告類 排版類 單元測(cè)試類 URI 類 User-Agent 類 表單驗(yàn)證 XML-RPC 和 XML-RPC 服務(wù)器 Zip 編碼類 緩存適配器 適配器參考 適配器 數(shù)據(jù)庫(kù)類 Active Record 類 數(shù)據(jù)庫(kù)緩存類 自定義函數(shù)調(diào)用 數(shù)據(jù)庫(kù)配置 連接你的數(shù)據(jù)庫(kù) 數(shù)據(jù)庫(kù)快速入門例子代碼 字段數(shù)據(jù) 數(shù)據(jù)庫(kù)維護(hù)類 查詢輔助函數(shù) 數(shù)據(jù)庫(kù)類 查詢 生成查詢記錄集 表數(shù)據(jù) 事務(wù) 數(shù)據(jù)庫(kù)工具類 JavaScript類 輔助函數(shù)參考 數(shù)組輔助函數(shù) CAPTCHA 輔助函數(shù) Cookie Helper 日期輔助函數(shù) 目錄輔助函數(shù) 下載輔助函數(shù) Email 輔助函數(shù) 文件輔助函數(shù) 表單輔助函數(shù) HTML輔助函數(shù) Inflector 輔助函數(shù) 語(yǔ)言輔助函數(shù) 數(shù)字輔助函數(shù) 路徑輔助函數(shù) 安全輔助函數(shù) 表情輔助函數(shù) 字符串輔助函數(shù) 文本輔助函數(shù) 排版輔助函數(shù) URL 輔助函數(shù) XML 輔助函數(shù)
Figuren

CodeIgniter 用戶指南 版本 2.1.0

編輯文檔、查看近期更改請(qǐng) 登錄 或 注冊(cè)  找回密碼
查看原文

HTML 表格類

表格類提供了多個(gè)函數(shù),允許你從數(shù)組或者數(shù)據(jù)庫(kù)結(jié)果集中自動(dòng)生成HTML表格。

初始化類

像CodeIgniter的其它類一樣, 在控制器中使用$this->load->library 函數(shù)來(lái)初始化表格類:

$this->load->library('table');

一旦被加載,可以這樣建立一個(gè)表格庫(kù)對(duì)象的實(shí)例: $this->table

例子

此例演示如何通過(guò)一個(gè)多維數(shù)組(multi-dimensional array)自動(dòng)生成表格。 注意:數(shù)組的第一個(gè)索引將成為表頭(或者你可以通過(guò)set_heading()函數(shù)自定義表頭)。

$this->load->library('table');

$data = array(
?????????????array('Name', 'Color', 'Size'),
?????????????array('Fred', 'Blue', 'Small'),
?????????????array('Mary', 'Red', 'Large'),
?????????????array('John', 'Green', 'Medium')
?????????????);

echo $this->table->generate($data);

這里是一個(gè)由數(shù)據(jù)庫(kù)查詢結(jié)構(gòu)創(chuàng)建而成的表格例子。表格類會(huì)基于表格的名字自動(dòng)地生成表格標(biāo)題(參考下面記述的函數(shù),你可以使用set_heading()函數(shù)設(shè)置你自己的標(biāo)題)。

$this->load->library('table');

$query = $this->db->query("SELECT * FROM my_table");

echo $this->table->generate($query);

此例演示了如何使用連續(xù)的參數(shù)創(chuàng)建一個(gè)表格:

$this->load->library('table');

$this->table->set_heading('Name', 'Color', 'Size');

$this->table->add_row('Fred', 'Blue', 'Small');
$this->table->add_row('Mary', 'Red', 'Large');
$this->table->add_row('John', 'Green', 'Medium');

echo $this->table->generate();

這個(gè)簡(jiǎn)單的例子,除了更換個(gè)別的參數(shù)外,還使用了數(shù)組:

$this->load->library('table');

$this->table->set_heading(array('Name', 'Color', 'Size'));

$this->table->add_row(array('Fred', 'Blue', 'Small'));
$this->table->add_row(array('Mary', 'Red', 'Large'));
$this->table->add_row(array('John', 'Green', 'Medium'));

echo $this->table->generate();

修改表格的外觀

表格類允許你以你指定的設(shè)計(jì)編排,去設(shè)置表格模板。這里是模板的原型:

$tmpl = array (
????????????????????'table_open'??????????=> '<table border="0" cellpadding="4" cellspacing="0">',

????????????????????'heading_row_start'???=> '<tr>',
????????????????????'heading_row_end'?????=> '</tr>',
????????????????????'heading_cell_start'??=> '<th>',
????????????????????'heading_cell_end'????=> '</th>',

????????????????????'row_start'???????????=> '<tr>',
????????????????????'row_end'?????????????=> '</tr>',
????????????????????'cell_start'??????????=> '<td>',
????????????????????'cell_end'????????????=> '</td>',

????????????????????'row_alt_start'???????=> '<tr>',
????????????????????'row_alt_end'?????????=> '</tr>',
????????????????????'cell_alt_start'??????=> '<td>',
????????????????????'cell_alt_end'????????=> '</td>',

????????????????????'table_close'?????????=> '</table>'
??????????????);

$this->table->set_template($tmpl);

注意:? 在這個(gè)模板,你會(huì)發(fā)現(xiàn)這里有兩個(gè)"row"塊設(shè)置項(xiàng)。 這是允許你創(chuàng)建隔行顏色,或者設(shè)計(jì)每行數(shù)據(jù)的重復(fù)間隔元素。

你不必提交全部的模板。如果你只想改變編排的一部分,你可以簡(jiǎn)單地提交那部分的元素。在這個(gè)例子里,只有表格的開(kāi)始標(biāo)簽被更改:

$tmpl = array ( 'table_open'??=> '<table border="1" cellpadding="2" cellspacing="1" class="mytable">' );

$this->table->set_template($tmpl);

函數(shù)參考

$this->table->generate()

返回一個(gè)包含生成的表格的字符串。 接受一個(gè)可選的參數(shù),該參數(shù)可以是一個(gè)數(shù)組或是從數(shù)據(jù)庫(kù)獲取的結(jié)果對(duì)象。

$this->table->set_caption()

允許你給表格添加一個(gè)標(biāo)題

$this->table->set_caption('Colors');

$this->table->set_heading()

允許你設(shè)置表格的表頭。你可以提交一個(gè)數(shù)組或分開(kāi)的參數(shù):

$this->table->set_heading('Name', 'Color', 'Size'); $this->table->set_heading(array('Name', 'Color', 'Size'));

$this->table->add_row()

允許你在你的表格中添加一行。你可以提交一個(gè)數(shù)組或分開(kāi)的參數(shù):

$this->table->add_row('Blue', 'Red', 'Green'); $this->table->add_row(array('Blue', 'Red', 'Green'));

如果你想要單獨(dú)設(shè)置一個(gè)單元格的屬性,你可以使用一個(gè)關(guān)聯(lián)數(shù)組。關(guān)聯(lián)鍵名 'data' 定義了這個(gè)單元格的數(shù)據(jù)。其它的鍵值對(duì) key => val 將會(huì)以 key='val' 的形式被添加為該單元格的屬性:

$cell = array('data' => 'Blue', 'class' => 'highlight', 'colspan' => 2);
$this->table->add_row($cell, 'Red', 'Green');

// 生成
// <td class='highlight' colspan='2'>Blue</td><td>Red</td><td>Green</td>

$this->table->make_columns()

這個(gè)函數(shù)以一個(gè)一維數(shù)組為輸入,創(chuàng)建一個(gè)二維數(shù)組,它的深度和列數(shù)一樣。這個(gè)函數(shù)可以把一個(gè)帶有多個(gè)元素的單一數(shù)組根據(jù)表格的列數(shù)進(jìn)行整理并顯示。參考下面的例子:

$list = array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve');

$new_list = $this->table->make_columns($list, 3);

$this->table->generate($new_list);

// Generates a table with this prototype

<table border="0" cellpadding="4" cellspacing="0">
<tr>
<td>one</td><td>two</td><td>three</td>
</tr><tr>
<td>four</td><td>five</td><td>six</td>
</tr><tr>
<td>seven</td><td>eight</td><td>nine</td>
</tr><tr>
<td>ten</td><td>eleven</td><td>twelve</td></tr>
</table>

$this->table->set_template()

允許你設(shè)置你的模板。你可以提交整個(gè)模板或局部模板。

$tmpl = array ( 'table_open'??=> '<table border="1" cellpadding="2" cellspacing="1" class="mytable">' );

$this->table->set_template($tmpl);

$this->table->set_empty()

使你能設(shè)置一個(gè)默認(rèn)值,用來(lái)顯示在表格中內(nèi)容為空的單元格。 例如,你可以設(shè)置一個(gè)non-breaking space(用來(lái)防止表格邊框破損的空格):

$this->table->set_empty("&nbsp;");

$this->table->clear()

使你能清除表格的表頭和行中的數(shù)據(jù)。如果你需要顯示多個(gè)有不同數(shù)據(jù)的表格,那么你需要在每個(gè)表格生成之后調(diào)用這個(gè)函數(shù)來(lái)清除之前表格的信息。例如:

$this->load->library('table');

$this->table->set_heading('Name', 'Color', 'Size');
$this->table->add_row('Fred', 'Blue', 'Small');
$this->table->add_row('Mary', 'Red', 'Large');
$this->table->add_row('John', 'Green', 'Medium');

echo $this->table->generate();

$this->table->clear();

$this->table->set_heading('Name', 'Day', 'Delivery');
$this->table->add_row('Fred', 'Wednesday', 'Express');
$this->table->add_row('Mary', 'Monday', 'Air');
$this->table->add_row('John', 'Saturday', 'Overnight');

echo $this->table->generate();

$this->table->function

允許你指定一個(gè)本地的PHP方法或一個(gè)有效的方法應(yīng)用到所有的單元格中的數(shù)據(jù)的數(shù)組對(duì)象。

$this->load->library('table');

$this->table->set_heading('Name', 'Color', 'Size');
$this->table->add_row('Fred', '<strong>Blue</strong>', 'Small');

$this->table->function = 'htmlspecialchars';
echo $this->table->generate();

在上面的例子中,所有單元格中的數(shù)據(jù)都可以通過(guò)PHP的htmlspecialchars()方法實(shí)現(xiàn)html轉(zhuǎn)義,其結(jié)果如下:

<td>Fred</td><td>&lt;strong&gt;Blue&lt;/strong&gt;</td><td>Small</td>

?

翻譯貢獻(xiàn)者: architectcom, bnlt, Hex, huangnaiang, KilluaVX, tanqimin, vidon, Xwoder, yinzhili
最后修改: 2011-11-22 09:47:50
Vorheriger Artikel: N?chster Artikel: