From 38070c1ebcddbb7500eca3603ed2d8cbc4d1d561 Mon Sep 17 00:00:00 2001 From: Weichen Lin Date: Sat, 4 May 2013 23:26:45 +0800 Subject: [PATCH 1/8] translate general/libraries.html --- general/libraries.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/general/libraries.html b/general/libraries.html index 2271ff0..c7d85b4 100644 --- a/general/libraries.html +++ b/general/libraries.html @@ -68,7 +68,10 @@

使用 CodeIgniter 程式庫

只要載入後,你就可以依照教學手冊的相關章節來使用它:

+ +

你還可以一次載入多個程式庫,只要傳入一個包含多個程式庫的陣列即可,例如下面這樣:

$this->load->library(array('email', 'table')); From b756f161bd48b451e784ba24c3247772dde72dea Mon Sep 17 00:00:00 2001 From: Weichen Lin Date: Sun, 5 May 2013 02:54:25 +0800 Subject: [PATCH 2/8] translate general/creating_libraries.html, also add extra example about config file for library --- general/creating_libraries.html | 136 ++++++++++++++++++++++++++++---- 1 file changed, 122 insertions(+), 14 deletions(-) diff --git a/general/creating_libraries.html b/general/creating_libraries.html index 0502627..627e66b 100644 --- a/general/creating_libraries.html +++ b/general/creating_libraries.html @@ -59,25 +59,31 @@

建立自己的程式庫

當我們使用"程式庫(Libraries)"這個名稱的時候, 我們通常指的是位在 libraries 目錄底下的類別, 詳細可參考使用手冊中的類別參考的說明。 + +而在這邊,我們要教你的是如何在 application/libraries 建立你自己的程式庫。這是為了將你的程式庫與CodeIgniter內建的區分開來。

+ +

CodeIgniter允許你繼承(extend)原有的類別以擴充新功能。你也可以直接取代掉原本的類別,只要你使用與原有類別相同的名稱並放進 application/libraries 資料夾裡即可。

總結歸納:

底下詳細解釋這三個概念。

- + +

注意: 只有資料庫相關的類別無法被繼承,也無法用你自己的版本取代。其他的類別都可以。

存檔位置

@@ -145,13 +151,57 @@

於初使化自定類別時傳遞參數

    }
}

?> - + +

你也可以使用設定檔來存放設定值,只要在 application/config/ 資料夾裡,建立一個與類別 小寫檔案名稱 相同的檔案即可。 +但若是你使用上面所述的方式,由參數來傳入設定值,則設定檔就不會被使用。請參考下面的範例。

+

我們修改Someclass,對參數做些動作:

+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+
+class Someclass {
+
+    private $params_str; +    public function __construct($params)
+    {
+        // Do something with $params
+        $this->params_str .= "foo={$params['foo']}";
+        $this->params_str .= ",and bar={$params['bar']}";
+    }
+    public function get_params_str()
+    {
+        return $this->params_str;
+    }
+}

+?>
+

然後給 Someclass 建立一個設定檔,放在 application/config/someclass.php

+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +

+$config['foo'] = 'foo_from_config';
+$config['bar'] = 'bar_from_config';
+
+/* End of file someclass.php */
+

你可以比較兩種方式不同的結果:

+ +$params = array(
+    'foo' => 'foo_from_param',
+    'bar' => 'bar_from_param'
+);
+
+// 由參數傳入設定值
+$this->load->library('Someclass', $params);
+$this->someclass->get_params_str();
+
+// 或是自動讀取設定檔之設定值
+$this->load->library('Someclass');
+$this->someclass->get_params_str();
+
+
@@ -159,27 +209,39 @@

於初使化自定類別時傳遞參數

在您的程式裡面使用 CodeIgniter 資源

+ +

使用函式 get_instance() 可以讓你在自己的程式庫中取得 CodeIgniter 的資源,這個函式將傳回 CodeIgniter 的 super object。

+ +

通常你可以在你的 controller 函式裡直接使用 $this 來呼叫 CodeIgniter 的函式:

$this->load->helper('url');
$this->load->library('session');
$this->config->item('base_url');
-etc. +// 以此類推
+ +

然而,這僅在 controllers, models 或是 views 能夠使用。若是你想在你自己製作的類別中使用 CodeIgniter 的類別,你可以這樣做:

+ +

首先,取得 CodeIgniter 物件並存放到變數中:

$CI =& get_instance(); + +

當你將物件放到變數中,你就可以使用這個變數來取代 $this

$CI =& get_instance();
@@ -187,56 +249,91 @@

在您的程式裡面使用 CodeIgniter 資源

$CI->load->helper('url');
$CI->load->library('session');
$CI->config->item('base_url');
-etc. +// 以此類推
+ +

注意: 你會發現範例中 get_instance() 時使用了 & 以取得物件的參考: +

+$CI =& get_instance(); +
+
+這非常非常重要!! 取得物件的參考可以讓你使用同一個 CodeIgniter 物件,而不是複製一個副本。

-

原生程式庫替換至個人版本(Replacing Native Libraries with Your Versions)

+

使用個人版本替換原生程式庫

+ +

只要讓你的類別檔案使用與原生程式庫相同的檔案名稱,CodeIgniter 就會自動用它來代替原本的函式庫。 +要這麼做,你必須讓檔案名稱與類別名稱都與要替換的原生程式庫完全相同才行。 +例如,要取代掉原本的 Email 程式庫,你必須在 application/libraries/Email.php 建立一個檔案,並宣告你的類別為:

class CI_Email {

}
+ +

注意,大多數的原生類別名稱都使用 CI_ 做為前置字串。

+

這時只需要用標準的方式,就可以讀取你的版本:

$this->load->library('email'); + +

注意: 目前還無法使用你自己的類別來替換掉資料庫的類別。

+

繼承原生程式庫(Extending Native Libraries)

-

擴充原生程式庫(Extending Native Libraries)

- + +

如果你想要做的只是增加一些(可能一或兩個)函式給原有的程式庫,那就沒有必要將整個類別替換掉。這個時候使用繼承來擴充類別是更容易的方法。 +要繼承一個類別的作法,有點類似將其替換掉,但有以下的差別:

+ + + +

例如,繼承原生的 Email 類別,你必須建立一個檔案 application/libraries/MY_Email.php, +並這樣宣告你的類別:

class MY_Email extends CI_Email {

}
+ +

注意: 如果你需要在你的類別中使用建構子,那你也必須執行父類別的建構子:

class MY_Email extends CI_Email {
@@ -250,6 +347,7 @@

擴充原生程式庫(Extending Native Libraries)

載入子類別

+ +

要讀取你的子類別,使用標準的語法載入即可。注意不要包含前置字串,例如你要讀取上面範例中 Email 的子類別,你可以這樣做:

+ +$this->load->library('email'); + + +

載入成功後,你就可以像平常使用原生類別那樣使用這個子類別。在本例中,你可以這樣使用 email 類別:

$this->email->some_function(); From 905837100b122fee37a5154162e97b42467bc052 Mon Sep 17 00:00:00 2001 From: Weichen Lin Date: Sat, 11 May 2013 07:43:49 +0800 Subject: [PATCH 3/8] translate general/common_functions.html --- general/common_functions.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/general/common_functions.html b/general/common_functions.html index 0540840..2ae01e9 100644 --- a/general/common_functions.html +++ b/general/common_functions.html @@ -100,7 +100,10 @@

remove_invisible_characters($str)

html_escape($mixed)

+ +

此函數提供一個捷徑來呼叫 htmlspecialchars() 函數。它允許傳入字串或陣列。這對於避免跨網站腳本攻擊(XSS)很有用處。

From e7cb74a1b84fe9aa06583f180ac4a40b2a534460 Mon Sep 17 00:00:00 2001 From: Weichen Lin Date: Sat, 11 May 2013 10:56:05 +0800 Subject: [PATCH 4/8] translate libraries/pagination.html, add example for use_page_numbers --- libraries/pagination.html | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libraries/pagination.html b/libraries/pagination.html index b97133c..e299b5e 100644 --- a/libraries/pagination.html +++ b/libraries/pagination.html @@ -112,7 +112,17 @@

$config['num_links'] = 2;

放在您目前所在頁數前面跟後面所顯示的分頁數量。舉例來說,參數設定2,就會在前面跟後面兩邊多加兩個頁數,如同此頁最頂端的例子所顯示

$config['use_page_numbers'] = TRUE;

+ +

預設會在 URI 顯示你要分頁項目的索引編號,而不是頁數。如果你比較喜歡使用頁數,將這個值設定為 TRUE 。

+

+// 若每頁顯示二十個項目,則預設的第三頁 URI:
+http://example.com/index.php/test/page/40
+
+// 設定 $config['use_page_numbers'] = TRUE 後, URI:
+http://example.com/index.php/test/page/3
+

$config['page_query_string'] = TRUE;

在預設情況下,分頁類會假設您預設使用 URI Segments,並且建構您的連結就如同底下

From 534eaf8d0efabd5fa6adceb35b826627a9be10f2 Mon Sep 17 00:00:00 2001 From: Weichen Lin Date: Sun, 12 May 2013 17:15:33 +0800 Subject: [PATCH 5/8] translate libraries/output.html --- libraries/output.html | 68 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/libraries/output.html b/libraries/output.html index 4b751b7..ef13baf 100644 --- a/libraries/output.html +++ b/libraries/output.html @@ -58,53 +58,82 @@

Output 類別

+ +

Output 類別是一個小類別,其主要的功能是:將最終產生的網頁送交給客戶端瀏覽器。 +若你使用了快取的功能,它也負責快取你的網頁。

-

注意: This class is initialized automatically by the system so there is no need to do it manually.

+

注意:系統會自動初始這個類別, 所以不需要手動載入。

+ +

在一般的情況下你不會發現 Output 類別,因為它不需要你的介入便默默的在工作。 +例如,當你使用 Loader 類別去讀取一個 view 檔案,這個 view 檔案會被自動的傳給 Output 類別, +然後在系統執行的最後階段 CodeIgniter 會自動處理這些輸出步驟。當然,必要的話你也可以手動的去處理,只要使用下列兩個函式:

$this->output->set_output();

+ +

允許你手動設定最後輸出的字串。使用範例:

$this->output->set_output($data); + +

非常重要:如果你要自己操作輸出的功能,則必須放在最後一個步驟才做。 +例如,如果你正在你的一個 controller 函式中建立頁面,你只能在函式最後結束前才能使用output。

$this->output->set_content_type();

+ +

允許你設定頁面的 mime-type,如此一來你可以更輕鬆的提供 JSON、JPEG 及 XML 等等資料。

$this->output
    ->set_content_type('application/json')
    ->set_output(json_encode(array('foo' => 'bar')));

$this->output
-    ->set_content_type('jpeg') // You could also use ".jpeg" which will have the full stop removed before looking in config/mimes.php
+    ->set_content_type('jpeg') // 你也可以使用 ".jpeg","點號"會先被移掉才去查找 config/mimes.php
    ->set_output(file_get_contents('files/something.jpg'));
+ +

非常重要:確認你傳入的所有非mine的字串都有在 config/mimes.php 中設定好,否則不會運作。

$this->output->get_output();

+ +

允許你手動取回 Output 類別所存放的輸出資料。使用範例:

$string = $this->output->get_output(); + +

注意,只有在使用了像是 $this->load->view() 這樣的函式來將資料傳送給 Output 類別以後,你才能夠從 Output 類別取得輸出資料。

$this->output->append_output();

+ +

增加資料到輸出字串中。使用範例:

$this->output->append_output($data); @@ -112,7 +141,10 @@

$this->output->append_output();

$this->output->set_header();

+ +

允許你手動設定 HTTP header,這將在 Output 類別準備好頁面要輸出時一併送出。參考範例:

$this->output->set_header("HTTP/1.0 200 OK");
@@ -125,37 +157,61 @@

$this->output->set_header();

$this->output->set_status_header();

+ +

允許你手動設定 HTTP status。參考範例:

$this->output->set_status_header('401');
-// Sets the header as: Unauthorized
+// 設定 header: Unauthorized
-

See here for a full list of headers.

+

請參考:完整的 header 列表

$this->output->enable_profiler();

+ +

允許你啟用或停用 Profiler,這會在你的頁面底部顯示一些資料與數據,可以用來除錯或是最佳化。

+ +

若要啟用 Profiler,將下面的函式放在你的 Controller 當中任意地方。

$this->output->enable_profiler(TRUE); + +

當啟用之後,在你的網頁底部將會插入一些報表。

+ +

若要停用 Profiler 你可以這樣做:

$this->output->enable_profiler(FALSE);

$this->output->set_profiler_sections();

+ +

允許你啟用或停用 Profiler 特定的部份,請參考 Profiler 的文件 以取得更多資訊。

$this->output->cache();

+ +

CodeIgniter 輸出函式庫也可以控制快取,請參考caching 的文件

+ +

解析變數

+

CodeIgniter 預設會在輸出中解析這些虛擬變數:{elapsed_time}{memory_usage}。 +要停用這項功能,將 controller 的類別屬性$parse_exec_vars 設定為 FALSE

$this->output->parse_exec_vars = FALSE; From 9cdc2247468429483d363898821e7036efc8c6fb Mon Sep 17 00:00:00 2001 From: Weichen Lin Date: Sat, 1 Jun 2013 11:23:39 +0800 Subject: [PATCH 6/8] remove unnecessary comment --- general/common_functions.html | 3 -- general/creating_libraries.html | 85 --------------------------------- general/libraries.html | 3 -- libraries/output.html | 61 ----------------------- libraries/pagination.html | 3 -- 5 files changed, 155 deletions(-) diff --git a/general/common_functions.html b/general/common_functions.html index 2ae01e9..4b3d3d9 100644 --- a/general/common_functions.html +++ b/general/common_functions.html @@ -100,9 +100,6 @@

remove_invisible_characters($str)

html_escape($mixed)

-

此函數提供一個捷徑來呼叫 htmlspecialchars() 函數。它允許傳入字串或陣列。這對於避免跨網站腳本攻擊(XSS)很有用處。

diff --git a/general/creating_libraries.html b/general/creating_libraries.html index 627e66b..3a3e27b 100644 --- a/general/creating_libraries.html +++ b/general/creating_libraries.html @@ -59,16 +59,7 @@

建立自己的程式庫

當我們使用"程式庫(Libraries)"這個名稱的時候, 我們通常指的是位在 libraries 目錄底下的類別, 詳細可參考使用手冊中的類別參考的說明。 - 而在這邊,我們要教你的是如何在 application/libraries 建立你自己的程式庫。這是為了將你的程式庫與CodeIgniter內建的區分開來。

-

CodeIgniter允許你繼承(extend)原有的類別以擴充新功能。你也可以直接取代掉原本的類別,只要你使用與原有類別相同的名稱並放進 application/libraries 資料夾裡即可。

總結歸納:

@@ -80,9 +71,6 @@

建立自己的程式庫

底下詳細解釋這三個概念。

-

注意: 只有資料庫相關的類別無法被繼承,也無法用你自己的版本取代。其他的類別都可以。

存檔位置

@@ -151,11 +139,6 @@

於初使化自定類別時傳遞參數

    }
}

?>
-

你也可以使用設定檔來存放設定值,只要在 application/config/ 資料夾裡,建立一個與類別 小寫檔案名稱 相同的檔案即可。 但若是你使用上面所述的方式,由參數來傳入設定值,則設定檔就不會被使用。請參考下面的範例。

@@ -209,14 +192,7 @@

於初使化自定類別時傳遞參數

在您的程式裡面使用 CodeIgniter 資源

-

使用函式 get_instance() 可以讓你在自己的程式庫中取得 CodeIgniter 的資源,這個函式將傳回 CodeIgniter 的 super object。

-

通常你可以在你的 controller 函式裡直接使用 $this 來呼叫 CodeIgniter 的函式:

@@ -226,21 +202,11 @@

在您的程式裡面使用 CodeIgniter 資源

// 以此類推
-

然而,這僅在 controllers, models 或是 views 能夠使用。若是你想在你自己製作的類別中使用 CodeIgniter 的類別,你可以這樣做:

-

首先,取得 CodeIgniter 物件並存放到變數中:

$CI =& get_instance(); -

當你將物件放到變數中,你就可以使用這個變數來取代 $this

@@ -252,14 +218,6 @@

在您的程式裡面使用 CodeIgniter 資源

// 以此類推
-

注意: 你會發現範例中 get_instance() 時使用了 & 以取得物件的參考:

$CI =& get_instance(); @@ -269,11 +227,6 @@

在您的程式裡面使用 CodeIgniter 資源

使用個人版本替換原生程式庫

-

只要讓你的類別檔案使用與原生程式庫相同的檔案名稱,CodeIgniter 就會自動用它來代替原本的函式庫。 要這麼做,你必須讓檔案名稱與類別名稱都與要替換的原生程式庫完全相同才行。 例如,要取代掉原本的 Email 程式庫,你必須在 application/libraries/Email.php 建立一個檔案,並宣告你的類別為:

@@ -283,45 +236,23 @@

使用個人版本替換原生程式庫

} -

注意,大多數的原生類別名稱都使用 CI_ 做為前置字串。

這時只需要用標準的方式,就可以讀取你的版本:

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

注意: 目前還無法使用你自己的類別來替換掉資料庫的類別。

繼承原生程式庫(Extending Native Libraries)

-

如果你想要做的只是增加一些(可能一或兩個)函式給原有的程式庫,那就沒有必要將整個類別替換掉。這個時候使用繼承來擴充類別是更容易的方法。 要繼承一個類別的作法,有點類似將其替換掉,但有以下的差別:

- -

例如,繼承原生的 Email 類別,你必須建立一個檔案 application/libraries/MY_Email.php, 並這樣宣告你的類別:

@@ -330,9 +261,6 @@

繼承原生程式庫(Extending Native Libraries)

} -

注意: 如果你需要在你的類別中使用建構子,那你也必須執行父類別的建構子:

@@ -347,23 +275,10 @@

繼承原生程式庫(Extending Native Libraries)

載入子類別

-

要讀取你的子類別,使用標準的語法載入即可。注意不要包含前置字串,例如你要讀取上面範例中 Email 的子類別,你可以這樣做:

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

載入成功後,你就可以像平常使用原生類別那樣使用這個子類別。在本例中,你可以這樣使用 email 類別:

diff --git a/general/libraries.html b/general/libraries.html index c7d85b4..4c7c1f3 100644 --- a/general/libraries.html +++ b/general/libraries.html @@ -68,9 +68,6 @@

使用 CodeIgniter 程式庫

只要載入後,你就可以依照教學手冊的相關章節來使用它:

-

你還可以一次載入多個程式庫,只要傳入一個包含多個程式庫的陣列即可,例如下面這樣:

$this->load->library(array('email', 'table')); diff --git a/libraries/output.html b/libraries/output.html index ef13baf..d8d04ab 100644 --- a/libraries/output.html +++ b/libraries/output.html @@ -58,46 +58,26 @@

Output 類別

-

Output 類別是一個小類別,其主要的功能是:將最終產生的網頁送交給客戶端瀏覽器。 若你使用了快取的功能,它也負責快取你的網頁。

注意:系統會自動初始這個類別, 所以不需要手動載入。

-

在一般的情況下你不會發現 Output 類別,因為它不需要你的介入便默默的在工作。 例如,當你使用 Loader 類別去讀取一個 view 檔案,這個 view 檔案會被自動的傳給 Output 類別, 然後在系統執行的最後階段 CodeIgniter 會自動處理這些輸出步驟。當然,必要的話你也可以手動的去處理,只要使用下列兩個函式:

$this->output->set_output();

-

允許你手動設定最後輸出的字串。使用範例:

$this->output->set_output($data); -

非常重要:如果你要自己操作輸出的功能,則必須放在最後一個步驟才做。 例如,如果你正在你的一個 controller 函式中建立頁面,你只能在函式最後結束前才能使用output。

$this->output->set_content_type();

-

允許你設定頁面的 mime-type,如此一來你可以更輕鬆的提供 JSON、JPEG 及 XML 等等資料。

$this->output
@@ -108,31 +88,18 @@

$this->output->set_content_type();

    ->set_content_type('jpeg') // 你也可以使用 ".jpeg","點號"會先被移掉才去查找 config/mimes.php
    ->set_output(file_get_contents('files/something.jpg'));
-

非常重要:確認你傳入的所有非mine的字串都有在 config/mimes.php 中設定好,否則不會運作。

$this->output->get_output();

-

允許你手動取回 Output 類別所存放的輸出資料。使用範例:

$string = $this->output->get_output(); -

注意,只有在使用了像是 $this->load->view() 這樣的函式來將資料傳送給 Output 類別以後,你才能夠從 Output 類別取得輸出資料。

$this->output->append_output();

-

增加資料到輸出字串中。使用範例:

$this->output->append_output($data); @@ -141,9 +108,6 @@

$this->output->append_output();

$this->output->set_header();

-

允許你手動設定 HTTP header,這將在 Output 類別準備好頁面要輸出時一併送出。參考範例:

@@ -157,9 +121,6 @@

$this->output->set_header();

$this->output->set_status_header();

-

允許你手動設定 HTTP status。參考範例:

$this->output->set_status_header('401');
@@ -169,22 +130,11 @@

$this->output->set_status_header();

$this->output->enable_profiler();

-

允許你啟用或停用 Profiler,這會在你的頁面底部顯示一些資料與數據,可以用來除錯或是最佳化。

若要啟用 Profiler,將下面的函式放在你的 Controller 當中任意地方。

$this->output->enable_profiler(TRUE); -

當啟用之後,在你的網頁底部將會插入一些報表。

若要停用 Profiler 你可以這樣做:

@@ -192,22 +142,11 @@

$this->output->enable_profiler();

$this->output->set_profiler_sections();

-

允許你啟用或停用 Profiler 特定的部份,請參考 Profiler 的文件 以取得更多資訊。

$this->output->cache();

-

CodeIgniter 輸出函式庫也可以控制快取,請參考caching 的文件

-

解析變數

CodeIgniter 預設會在輸出中解析這些虛擬變數:{elapsed_time}{memory_usage}。 diff --git a/libraries/pagination.html b/libraries/pagination.html index e299b5e..c34fbbb 100644 --- a/libraries/pagination.html +++ b/libraries/pagination.html @@ -112,9 +112,6 @@

$config['num_links'] = 2;

放在您目前所在頁數前面跟後面所顯示的分頁數量。舉例來說,參數設定2,就會在前面跟後面兩邊多加兩個頁數,如同此頁最頂端的例子所顯示

$config['use_page_numbers'] = TRUE;

-

預設會在 URI 顯示你要分頁項目的索引編號,而不是頁數。如果你比較喜歡使用頁數,將這個值設定為 TRUE 。

// 若每頁顯示二十個項目,則預設的第三頁 URI:
From 2ed4c6b20bb4c1e46fca614f67b63c5678aa46f1 Mon Sep 17 00:00:00 2001 From: Weichen Lin Date: Sun, 2 Jun 2013 00:02:31 +0800 Subject: [PATCH 7/8] remove my personal note --- general/creating_libraries.html | 49 +-------------------------------- libraries/pagination.html | 9 +----- 2 files changed, 2 insertions(+), 56 deletions(-) diff --git a/general/creating_libraries.html b/general/creating_libraries.html index 3a3e27b..1b70deb 100644 --- a/general/creating_libraries.html +++ b/general/creating_libraries.html @@ -140,54 +140,7 @@

於初使化自定類別時傳遞參數

}

?>

你也可以使用設定檔來存放設定值,只要在 application/config/ 資料夾裡,建立一個與類別 小寫檔案名稱 相同的檔案即可。 -但若是你使用上面所述的方式,由參數來傳入設定值,則設定檔就不會被使用。請參考下面的範例。

- -

我們修改Someclass,對參數做些動作:

-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
-
-class Someclass {
-
-    private $params_str; -    public function __construct($params)
-    {
-        // Do something with $params
-        $this->params_str .= "foo={$params['foo']}";
-        $this->params_str .= ",and bar={$params['bar']}";
-    }
-    public function get_params_str()
-    {
-        return $this->params_str;
-    }
-}

-?>
- -

然後給 Someclass 建立一個設定檔,放在 application/config/someclass.php

-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); -

-$config['foo'] = 'foo_from_config';
-$config['bar'] = 'bar_from_config';
-
-/* End of file someclass.php */
- -

你可以比較兩種方式不同的結果:

- -$params = array(
-    'foo' => 'foo_from_param',
-    'bar' => 'bar_from_param'
-);
-
-// 由參數傳入設定值
-$this->load->library('Someclass', $params);
-$this->someclass->get_params_str();
-
-// 或是自動讀取設定檔之設定值
-$this->load->library('Someclass');
-$this->someclass->get_params_str();
-
-
- - - +但若是你使用上面所述的方式,由參數來傳入設定值,則設定檔就不會被使用。

在您的程式裡面使用 CodeIgniter 資源

diff --git a/libraries/pagination.html b/libraries/pagination.html index c34fbbb..68b61ed 100644 --- a/libraries/pagination.html +++ b/libraries/pagination.html @@ -113,16 +113,9 @@

$config['num_links'] = 2;

$config['use_page_numbers'] = TRUE;

預設會在 URI 顯示你要分頁項目的索引編號,而不是頁數。如果你比較喜歡使用頁數,將這個值設定為 TRUE 。

-

-// 若每頁顯示二十個項目,則預設的第三頁 URI:
-http://example.com/index.php/test/page/40
-
-// 設定 $config['use_page_numbers'] = TRUE 後, URI:
-http://example.com/index.php/test/page/3
-

$config['page_query_string'] = TRUE;

-

在預設情況下,分頁類會假設您預設使用 URI Segments,並且建構您的連結就如同底下

+

在預設情況下,分頁類會假設您預設使用 URI Segments,並且建構您的就如同底下

http://example.com/index.php/test/page/20

假如您把 $config['enable_query_strings'] 參數設定為 TRUE,您的連結將會自動地被查詢字串所改寫。這個選項可以明確的被設置。把 $config['page_query_string'] 設定為 TRUE,分頁連結將會變成:

http://example.com/index.php?c=test&m=page&per_page=20

From e3975ce9801212bdd4f719b2b9f292af1d99fdc2 Mon Sep 17 00:00:00 2001 From: Weichen Lin Date: Sun, 2 Jun 2013 00:06:08 +0800 Subject: [PATCH 8/8] recover text deleted by mistake --- libraries/pagination.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/pagination.html b/libraries/pagination.html index 68b61ed..a0a7247 100644 --- a/libraries/pagination.html +++ b/libraries/pagination.html @@ -115,7 +115,7 @@

$config['use_page_numbers'] = TRUE;

預設會在 URI 顯示你要分頁項目的索引編號,而不是頁數。如果你比較喜歡使用頁數,將這個值設定為 TRUE 。

$config['page_query_string'] = TRUE;

-

在預設情況下,分頁類會假設您預設使用 URI Segments,並且建構您的就如同底下

+

在預設情況下,分頁類會假設您預設使用 URI Segments,並且建構您的連結就如同底下

http://example.com/index.php/test/page/20

假如您把 $config['enable_query_strings'] 參數設定為 TRUE,您的連結將會自動地被查詢字串所改寫。這個選項可以明確的被設置。把 $config['page_query_string'] 設定為 TRUE,分頁連結將會變成:

http://example.com/index.php?c=test&m=page&per_page=20