diff --git a/general/common_functions.html b/general/common_functions.html index 0540840..4b3d3d9 100644 --- a/general/common_functions.html +++ b/general/common_functions.html @@ -100,7 +100,7 @@

remove_invisible_characters($str)

html_escape($mixed)

-

This function provides short cut for htmlspecialchars() function. It accepts string and array. To prevent Cross Site Scripting (XSS), it is very useful.

+

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

diff --git a/general/creating_libraries.html b/general/creating_libraries.html index 0502627..1b70deb 100644 --- a/general/creating_libraries.html +++ b/general/creating_libraries.html @@ -59,25 +59,19 @@

建立自己的程式庫

當我們使用"程式庫(Libraries)"這個名稱的時候, 我們通常指的是位在 libraries 目錄底下的類別, 詳細可參考使用手冊中的類別參考的說明。 -In this case, however, we will instead describe how you can create -your own libraries within your application/libraries directory in order to maintain separation between your local resources -and the global framework resources.

- -

As an added bonus, CodeIgniter permits your libraries to extend native classes if you simply need to add some functionality -to an existing library. Or you can even replace native libraries just by placing identically named versions in your application/libraries folder.

+而在這邊,我們要教你的是如何在 application/libraries 建立你自己的程式庫。這是為了將你的程式庫與CodeIgniter內建的區分開來。

+

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

總結歸納:

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

- -

Note: The Database classes can not be extended or replaced with your own classes. All other classes are able to be replaced/extended.

- +

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

存檔位置

@@ -145,41 +139,28 @@

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

    }
}

?> - -

You can also pass parameters stored in a config file. Simply create a config file named identically to the class file name -and store it in your application/config/ folder. Note that if you dynamically pass parameters as described above, -the config file option will not be available.

- - - - - - +

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

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

-

To access CodeIgniter's native resources within your library use the get_instance() function. -This function returns the CodeIgniter super object.

- -

Normally from within your controller functions you will call any of the available CodeIgniter functions using the $this construct:

+

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

+

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

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

$this, however, only works directly within your controllers, your models, or your views. -If you would like to use CodeIgniter's classes from within your own custom classes you can do so as follows:

- - -

First, assign the CodeIgniter object to a variable:

+

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

+

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

$CI =& get_instance(); -

Once you've assigned the object to a variable, you'll use that variable instead of $this:

+

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

$CI =& get_instance();
@@ -187,56 +168,53 @@

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

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

注意: You'll notice that the above get_instance() function is being passed by reference: +

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

$CI =& get_instance();

-This is very important. Assigning by reference allows you to use the original CodeIgniter object rather than creating a copy of it.

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

-

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

-

Simply by naming your class files identically to a native library will cause CodeIgniter to use it instead of the native one. To use this -feature you must name the file and the class declaration exactly the same as the native library. For example, to replace the native Email library -you'll create a file named application/libraries/Email.php, and declare your class with:

+

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

+

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

class CI_Email {

}
-

Note that most native classes are prefixed with CI_.

- -

To load your library you'll see the standard loading function:

+

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

+

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

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

注意: At this time the Database 類別es can not be replaced with your own versions.

+

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

+

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

-

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

- -

If all you need to do is add some functionality to an existing library - perhaps add a function or two - then -it's overkill to replace the entire library with your version. In this case it's better to simply extend the class. -Extending a class is nearly identical to replacing a class with a couple exceptions:

+

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

-

For example, to extend the native Email class you'll create a file named application/libraries/MY_Email.php, and declare your class with:

+

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

class MY_Email extends CI_Email {

}
-

注意: If you need to use a constructor in your class make sure you extend the parent constructor:

- +

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

class MY_Email extends CI_Email {
@@ -250,13 +228,11 @@

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

載入子類別

-

To load your sub-class you'll use the standard syntax normally used. DO NOT include your prefix. For example, -to load the example above, which extends the Email 類別, you will use:

+

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

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

Once loaded you will use the class variable as you normally would for the class you are extending. In the case of -the email class all calls will use:

+

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

$this->email->some_function(); diff --git a/general/libraries.html b/general/libraries.html index 2271ff0..4c7c1f3 100644 --- a/general/libraries.html +++ b/general/libraries.html @@ -68,7 +68,7 @@

使用 CodeIgniter 程式庫

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

-

Additionally, multiple libraries can be loaded at the same time by passing an array of libraries to the load function.

+

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

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

Output 類別

-

The Output class is a small class with one main function: To send the finalized web page to the requesting browser. It is -also responsible for caching your web pages,if you use that feature.

+

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

-

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

+

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

-

Under normal circumstances you won't even notice the Output class since it works transparently without your intervention. -For example,when you use the Loader class to load a view file,it's automatically -passed to the Output class,which will be called automatically by CodeIgniter at the end of system execution. -It is possible,however,for you to manually intervene with the output if you need to,using either of the two following functions:

+

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

$this->output->set_output();

-

Permits you to manually set the final output string. 使用範例:

+

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

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

非常重要: If you do set your output manually,it must be the last thing done in the function you call it from. -For example,if you build a page in one of your controller functions,don't set the output until the end.

+

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

$this->output->set_content_type();

-

Permits you to set the mime-type of your page so you can serve JSON data, JPEG's, XML, etc easily.

+

允許你設定頁面的 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'));
-

Important: Make sure any non-mime string you pass to this method exists in config/mimes.php or it will have no effect.

- +

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

$this->output->get_output();

-

Permits you to manually retrieve any output that has been sent for storage in the output class. 使用範例:

+

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

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

Note that data will only be retrievable from this function if it has been previously sent to the output class by one of the -CodeIgniter functions like $this->load->view().

- +

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

$this->output->append_output();

-

Appends data onto the output string. Usage example:

+

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

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

$this->output->append_output();

$this->output->set_header();

-

Permits you to manually set server headers,which the output class will send for you when outputting the final rendered display. 參考範例:

+

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

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

$this->output->set_header();

$this->output->set_status_header();

-

Permits you to manually set a server 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();

-

Permits you to enable/disable the Profiler,which will display benchmark and other data -at the bottom of your pages for debugging and optimization purposes.

+

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

-

To enable the profiler place the following function anywhere within your Controller functions:

+

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

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

When enabled a report will be generated and inserted at the bottom of your pages.

+

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

-

To disable the profiler you will use:

+

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

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

$this->output->set_profiler_sections();

-

Permits you to enable/disable specific sections of the Profiler when enabled. Please refer to the Profiler documentation for further information.

+

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

$this->output->cache();

-

The CodeIgniter output library also controls caching. For more information,please see the caching documentation.

- -

Parsing Execution Variables

+

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

-

CodeIgniter will parse the pseudo-variables {elapsed_time} and {memory_usage} in your output by default. To disable this, set the $parse_exec_vars class property to FALSE in your controller. +

解析變數

+

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

$this->output->parse_exec_vars = FALSE; diff --git a/libraries/pagination.html b/libraries/pagination.html index b97133c..a0a7247 100644 --- a/libraries/pagination.html +++ b/libraries/pagination.html @@ -112,7 +112,7 @@

$config['num_links'] = 2;

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

$config['use_page_numbers'] = TRUE;

-

By default, the URI segment will use the starting index for the items you are paginating. If you prefer to show the the actual page number, set this to TRUE.

+

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

$config['page_query_string'] = TRUE;

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