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

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

CodeIgniter 用戶指南 版本 2.1.0

編輯文檔、查看近期更改請(qǐng) 登錄 或 注冊(cè)  找回密碼
查看原文

裝載類

裝載,顧名思義,是用來裝載元素。這些元素可以是庫(kù) (類) 視圖文件, 輔助函數(shù), 模型, 或者是你自己的文件。

提示: 這個(gè)類是由系統(tǒng)初始化的,所以,沒有必要自己手動(dòng)初始化。

以下為這個(gè)類里面的函數(shù):

$this->load->library('class_name', $config, 'object name')

這個(gè)函數(shù)是用來加載核心類。class_name 是你要加載的類的名稱。 提示: “類”和“庫(kù)”是可替換使用的。

比如,你想用 CodeIgniter 來發(fā)送郵件,第一步就是在你的控制器里加載 email 類。

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

一旦被加載,就可以使用該類了,?使用 $this->email->some_function()。

類庫(kù)文件可以被保存到主libraries目錄的子目錄下面,或者保存到個(gè)人的application/libraries 目錄下。 要載入子目錄下的文件,只需將路徑包含進(jìn)來就可以了,注意這里說的路徑是指相對(duì)于libraries目錄的路徑。 例如,當(dāng)你有一個(gè)文件保存在下面這個(gè)位置:

libraries/flavors/chocolate.php

你應(yīng)該使用下面的方式來載入它:

$this->load->library('flavors/chocolate');

你可以隨心所欲地將文件保存到多層的子目錄下。

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'));

設(shè)置選項(xiàng)

第二個(gè)參數(shù)是可選的,作用是允許你有選擇性地傳遞配置參數(shù)。一般來說你可以將參數(shù)以數(shù)組的形式傳遞過去:

$config = array (
??????????????????'mailtype' => 'html',
??????????????????'charset'? => 'utf-8,
??????????????????'priority' => '1'
???????????????);

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

配置參數(shù)通常也可以保存在一個(gè)配置文件中。每個(gè)類庫(kù)在其各自的頁面中都有詳細(xì)的說明,所以在使用類庫(kù)之前,你必須認(rèn)真閱讀它們的說明。

Please take note, when multiple libraries are supplied in an array for the first parameter, each will receive the same parameter information.

給類庫(kù)分配不同的對(duì)象名

第三個(gè)參數(shù)也是可選的,如果為空,類庫(kù)通常就會(huì)被賦值給一個(gè)與類庫(kù)同名的對(duì)象。例如,如果類庫(kù)名為 Session, 它將會(huì)被賦值給一個(gè)名為 $this->session 的變量。

如果你希望使用你的自定義名稱,你可以通過第三個(gè)參數(shù)把它傳遞過去:

$this->load->library('session', '', 'my_session');

// Session 類現(xiàn)在可以通過下面的方式訪問:

$this->my_session

Please take note, when multiple libraries are supplied in an array for the first parameter, this parameter is discarded.

$this->load->view('file_name', $data, true/false)

這個(gè)函數(shù)是用來加載你的視圖文件。 如果你尚未閱讀本手冊(cè)視圖 章節(jié)的話,建議你先去閱讀那里的內(nèi)容,會(huì)有更詳細(xì)的函數(shù)使用說明.

第一個(gè)參數(shù)是必須的. 指定你要載入的視圖文件的名稱. ?注意: 無需加上 .php 擴(kuò)展名,除非你使用了其他的擴(kuò)展名。

第二個(gè)參數(shù) optional 允許你傳入數(shù)組或?qū)ο? 傳入的數(shù)組或?qū)ο髮⑹褂?php extract 函數(shù)導(dǎo)出,你可以在視圖中任意使用這些導(dǎo)出的變量. 此外,請(qǐng)閱讀 視圖 章節(jié)了解該功能的更多用法.

第三個(gè)參數(shù)是可選的,作用是改變函數(shù)的運(yùn)行方式,將數(shù)據(jù)以字符串的形式返回,而不是發(fā)送給瀏覽器。當(dāng)你希望用不同的方式處理數(shù)據(jù)時(shí),這個(gè)參數(shù)就非常有用。如果你將這個(gè)參數(shù)設(shè)置為 true (布爾型),函數(shù)就會(huì)返回?cái)?shù)據(jù)。這個(gè)參數(shù)的默認(rèn)值是 false, 也就是數(shù)據(jù)將會(huì)被發(fā)送給瀏覽器。如果你希望數(shù)據(jù)被返回,記得要將它賦值給一個(gè)變量:

$string = $this->load->view('myfile', '', true);

$this->load->model('Model_name');

$this->load->model('Model_name');

如果你的模型位于models目錄的子目錄下,那么,相對(duì)路徑也必須被包含進(jìn)來。例如,如果你有一個(gè)模型位于 application/models/blog/queries.php ,你應(yīng)該使用下面的語句來載入它:

$this->load->model('blog/queries');

如果你希望給模型賦予一個(gè)你自定義的對(duì)象名,請(qǐng)?jiān)诤瘮?shù)的第二個(gè)參數(shù)中給出你自定義的名稱:

$this->load->model('Model_name', 'fubar');

$this->fubar->function();

$this->load->database('options', true/false)

這個(gè)函數(shù)的作用是載入數(shù)據(jù)庫(kù)類。這兩個(gè)參數(shù)都是可選的。請(qǐng)查看 數(shù)據(jù)庫(kù) 段落以獲取更多信息。

$this->load->vars($array)

這個(gè)函數(shù)以一個(gè)關(guān)聯(lián)數(shù)組作為輸入?yún)?shù),將這個(gè)數(shù)組用PHP的extract函數(shù), 轉(zhuǎn)化成與這個(gè)數(shù)組對(duì)應(yīng)的變量.這個(gè)函數(shù)如果用第二個(gè)參數(shù),將產(chǎn)生和上面的$this->load->view()相同的結(jié)果 .你之所以要單獨(dú)用這個(gè)函數(shù)也許是因?yàn)?你想在控制器的構(gòu)造函數(shù)中設(shè)置一些全局變量,以使這些變量在任意函數(shù)調(diào)用的視圖(view)里能夠用上.你能多次調(diào)用這個(gè)函數(shù).數(shù)組數(shù)據(jù)被緩存并被并入一個(gè)數(shù)組,用來轉(zhuǎn)化成變量.

$this->load->get_var($key)

This function checks the associative array of variables available to your views. This is useful if for any reason a var is set in a library or another controller method using $this->load->vars().

$this->load->helper('file_name')

這個(gè)函數(shù)的作用是載入輔助函數(shù), file_name 是輔助函數(shù)對(duì)應(yīng)的文件名,不包括 _helper.php 擴(kuò)展名。

$this->load->file('filepath/filename', true/false)

這是一個(gè)通用的文件載入函數(shù)。在第一個(gè)參數(shù)中給出文件所在的路徑和文件名,對(duì)應(yīng)的文件將會(huì)被打開。默認(rèn)情況下,數(shù)據(jù)會(huì)被發(fā)送給瀏覽器,就如同視圖文件一樣,但如果你將第二個(gè)參數(shù)設(shè)置為 true (布爾型) 那么數(shù)據(jù)就會(huì)以字符串的形式被返回,而不是發(fā)送給瀏覽器。

$this->load->language('file_name')

這個(gè)函數(shù)是 語言加載函數(shù): $this->lang->load() 的一個(gè)別名。

$this->load->config('file_name')

這個(gè)函數(shù)是 配置文件加載函數(shù): $this->config->load() 的一個(gè)別名。

Application "Packages"

An application package allows for the easy distribution of complete sets of resources in a single directory, complete with its own libraries, models, helpers, config, and language files. It is recommended that these packages be placed in the application/third_party folder. Below is a sample map of an package directory

Sample Package "Foo Bar" Directory Map

The following is an example of a directory for an application package named "Foo Bar".

/application/third_party/foo_bar

config/
helpers/
language/
libraries/
models/

Whatever the purpose of the "Foo Bar" application package, it has its own config files, helpers, language files, libraries, and models. To use these resources in your controllers, you first need to tell the Loader that you are going to be loading resources from a package, by adding the package path.

$this->load->add_package_path()

Adding a package path instructs the Loader class to prepend a given path for subsequent requests for resources. As an example, the "Foo Bar" application package above has a library named Foo_bar.php. In our controller, we'd do the following:

$this->load->add_package_path(APPPATH.'third_party/foo_bar/');
$this->load->library('foo_bar');

$this->load->remove_package_path()

When your controller is finished using resources from an application package, and particularly if you have other application packages you want to work with, you may wish to remove the package path so the Loader no longer looks in that folder for resources. To remove the last path added, simply call the method with no parameters.

$this->load->remove_package_path()

Or to remove a specific package path, specify the same path previously given to add_package_path() for a package.:

$this->load->remove_package_path(APPPATH.'third_party/foo_bar/');

Package view files

By Default, package view files paths are set when add_package_path() is called. View paths are looped through, and once a match is encountered that view is loaded.

In this instance, it is possible for view naming collisions within packages to occur, and possibly the incorrect package being loaded. To ensure against this, set an optional second parameter of FALSE when calling add_package_path().

$this->load->add_package_path(APPPATH.'my_app', TRUE);
$this->load->view('my_app_index'); // Loads
$this->load->view('welcome_message'); // Will not load the default welcome_message b/c the second param to add_package_path is TRUE

// Reset things
$this->load->remove_package_path(APPPATH.'my_app');

// Again without the second parameter:
$this->load->add_package_path(APPPATH.'my_app', TRUE);
$this->load->view('my_app_index'); // Loads
$this->load->view('welcome_message'); // Loads

?

翻譯貢獻(xiàn)者: cookieu, Hex, tg8866, weelia, Xwoder, yinzhili
最后修改: 2012-02-06 01:06:30
上一篇: 下一篇: