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

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

CodeIgniter 用戶指南 版本 2.1.0

編輯文檔、查看近期更改請 登錄 或 注冊  找回密碼
查看原文

HTML 表格類

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

初始化類

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

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

一旦被加載,可以這樣建立一個表格庫對象的實例: $this->table

例子

此例演示如何通過一個多維數(shù)組(multi-dimensional array)自動生成表格。 注意:數(shù)組的第一個索引將成為表頭(或者你可以通過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);

這里是一個由數(shù)據(jù)庫查詢結(jié)構(gòu)創(chuà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)建一個表格:

$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();

這個簡單的例子,除了更換個別的參數(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è)計編排,去設(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);

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

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

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

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

函數(shù)參考

$this->table->generate()

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

$this->table->set_caption()

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

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

$this->table->set_heading()

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

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

$this->table->add_row()

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

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

如果你想要單獨設(shè)置一個單元格的屬性,你可以使用一個關(guān)聯(lián)數(shù)組。關(guān)聯(lián)鍵名 'data' 定義了這個單元格的數(shù)據(jù)。其它的鍵值對 key => val 將會以 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()

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

$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è)置你的模板。你可以提交整個模板或局部模板。

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

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

$this->table->set_empty()

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

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

$this->table->clear()

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

$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

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

$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ù)都可以通過PHP的htmlspecialchars()方法實現(xiàn)html轉(zhuǎn)義,其結(jié)果如下:

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

?

翻譯貢獻者: architectcom, bnlt, Hex, huangnaiang, KilluaVX, tanqimin, vidon, Xwoder, yinzhili
最后修改: 2011-11-22 09:47:50
Previous article: Next article: