11############################
2- Creating Core System Classes
2+ 新增系統核心類別
33############################
44
5- Every time CodeIgniter runs there are several base classes that are
6- initialized automatically as part of the core framework. It is possible,
7- however, to swap any of the core system classes with your own versions
8- or even extend the core versions.
5+ 每次 CodeIgniter 執行時,有幾個基礎類別會自動初始化,成為核心框架的一部分。不過還是有可能用你自己的版本來置換甚至擴充這些系統核心類別。
96
10- **Most users will never have any need to do this, but the option to
11- replace or extend them does exist for those who would like to
12- significantly alter the CodeIgniter core. **
7+ **大部分的使用者永遠不會需要這樣做,但是這個選項還是保留給那些想要大幅置換或擴充 CodeIgniter 核心的人。 **
138
14- .. note :: Messing with a core system class has a lot of implications, so
15- make sure you know what you are doing before attempting it.
9+ .. note :: 介入核心系統可能引發許多隱藏的問題,所以請在這麼做之前確定你知道你自己在做什麼。
1610
17- System Class List
11+ 系統類別列表
1812=================
1913
20- The following is a list of the core system files that are invoked every
21- time CodeIgniter runs:
14+ 以下是一個系統核心檔案的清單,每次 CodeIgniter 執行時都會呼叫他們: :
2215
2316- Benchmark
2417- Config
@@ -35,48 +28,40 @@ time CodeIgniter runs:
3528- URI
3629- Utf8
3730
38- Replacing Core Classes
31+ 更換核心類別
3932======================
4033
41- To use one of your own system classes instead of a default one simply
42- place your version inside your local *application/core/ * directory::
34+ 要用你自己的系統核心類別來置換預設的,只要將你自己的版本放在 *application/core * 目錄裡: ::
4335
4436 application/core/some_class.php
4537
46- If this directory does not exist you can create it.
38+ 如果這個目錄不存在,你可以自己新增。
4739
48- Any file named identically to one from the list above will be used
49- instead of the one normally used.
40+ 任何與在上述清單中檔案名稱相符的檔案都會被載入,取代系統正常使用的。
5041
51- Please note that your class must use CI as a prefix. For example, if
52- your file is named Input.php the class will be named::
42+ 請注意,你的類別名稱必須使用 CI 作為前置字串。例如,如果你的檔案名稱是 Input.php ,那類別名稱將是: ::
5343
5444 class CI_Input {
5545
5646 }
5747
58- Extending Core Class
48+ 繼承核心類別
5949====================
6050
61- If all you need to do is add some functionality to an existing library -
62- perhaps add a method or two - then it's overkill to replace the entire
63- library with your version. In this case it's better to simply extend the
64- class. Extending a class is nearly identical to replacing a class with a
65- couple exceptions:
51+ 如果你所要做的只是在現存程式庫中加入一些功能,例如增加一兩個函數,那置換掉整個程式庫就太過火了。在這個狀況下,擴充類別是比較好的做法。擴充一個類別與用一些例外來取代一個類別幾乎是相同的: :
6652
67- - The class declaration must extend the parent class.
68- - Your new class name and filename must be prefixed with MY\_ (this
69- item is configurable. See below.).
53+ - 類別宣告必須繼承(extend)父類別
54+ - 你的新類別名稱與檔名必須使用 MY\_ 前置字串(這是可設定的,請見下述)。
7055
71- For example, to extend the native Input class you'll create a file named
72- application/core/MY_Input.php, and declare your class with::
56+ 例如,要擴充一個內建的 Input 類別,你要先新增檔名為 application/core/MY_Input.php 的檔案,然後這樣宣告你的類別: ::
7357
7458 class MY_Input extends CI_Input {
7559
7660 }
7761
78- .. note :: If you need to use a constructor in your class make sure you
79- extend the parent constructor::
62+ .. note :: 如果你需要在你的類別中使用建構函數(Constructor),確定有在裡面擴充父類別的建構函數(Constructor):
63+
64+ ::
8065
8166 class MY_Input extends CI_Input {
8267
@@ -86,13 +71,9 @@ application/core/MY_Input.php, and declare your class with::
8671 }
8772 }
8873
89- **Tip: ** Any functions in your class that are named identically to the
90- methods in the parent class will be used instead of the native ones
91- (this is known as "method overriding"). This allows you to substantially
92- alter the CodeIgniter core.
74+ **Tip: ** 你類別中任何與父類別中相同名稱的函數,將會取代父類別的(這一般叫做“方法覆蓋 method overriding”)。這個方式允許你實質上改變 CodeIgniter 的核心。
9375
94- If you are extending the Controller core class, then be sure to extend
95- your new class in your application controller's constructors.
76+ 如果你要擴充控制器(Controller)核心類別,請確定有在你的應用程式控制器(Controller)的建構函數(Constructor)中擴充你的新類別。
9677
9778::
9879
@@ -109,13 +90,11 @@ your new class in your application controller's constructors.
10990 }
11091 }
11192
112- Setting Your Own Prefix
93+ 自訂子類別的前綴字串
11394-----------------------
11495
115- To set your own sub-class prefix, open your
116- *application/config/config.php * file and look for this item::
96+ 要設定你自己的子類別前置字串,請編輯你的 *application/config/config.php * 檔案並修改下面的項目: ::
11797
11898 $config['subclass_prefix'] = 'MY_';
11999
120- Please note that all native CodeIgniter libraries are prefixed
121- with CI\_ so DO NOT use that as your prefix.
100+ 請注意,所有的 CodeIgniter 內建程式庫都使用 CI\_ 前綴字串,所以不要用它來當作你自己的前綴字串。
0 commit comments