<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # HTML 表格類 表格類提供了一些方法用于根據數組或數據庫結果集自動生成 HTML 的表格。 * [使用表格類](http://codeigniter.org.cn/user_guide/libraries/table.html#id1) * [初始化類](http://codeigniter.org.cn/user_guide/libraries/table.html#id2) * [例子](http://codeigniter.org.cn/user_guide/libraries/table.html#id3) * [修改表格樣式](http://codeigniter.org.cn/user_guide/libraries/table.html#id4) * [類參考](http://codeigniter.org.cn/user_guide/libraries/table.html#id5) ## [使用表格類](http://codeigniter.org.cn/user_guide/libraries/table.html#id6) ### [初始化類](http://codeigniter.org.cn/user_guide/libraries/table.html#id7) 跟 CodeIgniter 中的其他類一樣,可以在你的控制器中使用?$this->load->library()?方法加載表格類: ~~~ $this->load->library('table'); ~~~ 一旦加載,表格類就可以像下面這樣使用: ~~~ $this->table ~~~ ### [例子](http://codeigniter.org.cn/user_guide/libraries/table.html#id8) 下面這個例子向你演示了如何通過多維數組來創建一個表格。注意數組的第一行將會變成 表格的表頭(或者你也可以通過下面介紹的?set_heading()?方法來設置你自己的表頭)。 ~~~ $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); ~~~ 下面這個例子是通過數據庫查詢結果來創建一個表格。表格類將使用查詢結果的列名自動生成表頭 (或者你也可以通過下面介紹的?set_heading()?方法來設置你自己的表頭)。 ~~~ $this->load->library('table'); $query = $this->db->query('SELECT * FROM my_table'); echo $this->table->generate($query); ~~~ 下面這個例子演示了如何使用分開的參數來生成表格: ~~~ $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->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(); ~~~ ### [修改表格樣式](http://codeigniter.org.cn/user_guide/libraries/table.html#id9) 表格類可以允許你設置一個表格的模板,你可以通過它設計表格的樣式,下面是模板的原型: ~~~ $template = array( 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">', 'thead_open' => '<thead>', 'thead_close' => '</thead>', 'heading_row_start' => '<tr>', 'heading_row_end' => '</tr>', 'heading_cell_start' => '<th>', 'heading_cell_end' => '</th>', 'tbody_open' => '<tbody>', 'tbody_close' => '</tbody>', '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($template); ~~~ 注解 你會發現模板中有兩個 "row" 代碼塊,它可以讓你的表格每行使用交替的顏色, 或者其他的這種隔行的設計元素。 你不用設置整個模板,只需要設置你想修改的部分即可。在下面這個例子中,只有 table 的起始標簽需要修改: ~~~ $template = array( 'table_open' => '<table border="1" cellpadding="2" cellspacing="1" class="mytable">' ); $this->table->set_template($template); ~~~ 你也可以在配置文件中設置默認的模板。 ## [類參考](http://codeigniter.org.cn/user_guide/libraries/table.html#id10) classCI_Table $function = NULL 允許你指定一個原生的 PHP 函數或一個有效的函數數組對象,該函數會作用于所有的單元格數據。 ~~~ $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(); ~~~ 上例中,所有的單元格數據都會先通過 PHP 的?htmlspecialchars()?函數,結果如下: ~~~ <td>Fred</td><td>&lt;strong&gt;Blue&lt;/strong&gt;</td><td>Small</td> ~~~ generate([$table_data = NULL]) 參數: * **$table_data**?(mixed) -- Data to populate the table rows with 返回: HTML table 返回類型: string 返回生成的表格的字符串。 接受一個可選的參數,該參數可以是一個數組或是從數據庫獲取的結果對象。 set_caption($caption) 參數: * **$caption**?(string) -- Table caption 返回: CI_Table instance (method chaining) 返回類型: CI_Table 允許你給表格添加一個標題。 ~~~ $this->table->set_caption('Colors'); ~~~ set_heading([$args = array()[,?...]]) 參數: * **$args**?(mixed) -- An array or multiple strings containing the table column titles 返回: CI_Table instance (method chaining) 返回類型: CI_Table 允許你設置表格的表頭。你可以提交一個數組或分開的參數: > > > $this->table->set_heading('Name', 'Color', 'Size'); > > $this->table->set_heading(array('Name', 'Color', 'Size')); > > add_row([$args = array()[,?...]]) 參數: * **$args**?(mixed) -- An array or multiple strings containing the row values 返回: CI_Table instance (method chaining) 返回類型: CI_Table 允許你在你的表格中添加一行。你可以提交一個數組或分開的參數: > > > $this->table->add_row('Blue', 'Red', 'Green'); > > $this->table->add_row(array('Blue', 'Red', 'Green')); > > 如果你想要單獨設置一個單元格的屬性,你可以使用一個關聯數組。關聯數組的鍵名?**data**?定義了這個單元格的數據。 其它的鍵值對 key => val 將會以 key='val' 的形式被添加為該單元格的屬性里: > > > $cell = array('data' => 'Blue', 'class' => 'highlight', 'colspan' => 2); $this->table->add_row($cell, 'Red', 'Green'); > > // generates // BlueRedGreen > > make_columns([$array = array()[,?$col_limit = 0]]) 參數: * **$array**?(array) -- An array containing multiple rows' data * **$col_limit**?(int) -- Count of columns in the table 返回: An array of HTML table columns 返回類型: array 這個函數以一個一維數組為輸入,創建一個多維數組,它的深度(譯注:不是行數,而是每一行的元素個數)和列數一樣。 這個函數可以把一個含有多個元素的數組按指定列在表格中顯示出來。參考下面的例子: > > > $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 > > onetwothree fourfivesix seveneightnine teneleventwelve > > set_template($template) 參數: * **$template**?(array) -- An associative array containing template values 返回: TRUE on success, FALSE on failure 返回類型: bool 允許你設置你的模板。你可以提交整個模板或部分模板。 ~~~ $template = array( 'table_open' => '<table border="1" cellpadding="2" cellspacing="1" class="mytable">' ); $this->table->set_template($template); ~~~ set_empty($value) 參數: * **$value**?(mixed) -- Value to put in empty cells 返回:CI_Table instance (method chaining) 返回類型: CI_Table 用于設置當表格中的單元格為空時要顯示的默認值。例如,設置一個不換行空格(NBSP,non-breaking space): ~~~ $this->table->set_empty("&nbsp;"); ~~~ clear() 返回: CI_Table instance (method chaining) 返回類型: CI_Table 使你能清除表格的表頭和行中的數據。如果你需要顯示多個有不同數據的表格, 那么你需要在每個表格生成之后調用這個函數來清除之前表格的信息。例如: > > > $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(); > >
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看