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

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

編輯文檔、查看近期更改請 登錄 或 注冊  找回密碼
查看原文

裝載類

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

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

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

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

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

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

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

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

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

libraries/flavors/chocolate.php

你應該使用下面的方式來載入它:

$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ù)是可選的,作用是允許你有選擇性地傳遞配置參數(shù)。一般來說你可以將參數(shù)以數(shù)組的形式傳遞過去:

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

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

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

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

給類庫分配不同的對象名

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

如果你希望使用你的自定義名稱,你可以通過第三個參數(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)

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

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

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

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

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

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

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

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

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

如果你希望給模型賦予一個你自定義的對象名,請在函數(shù)的第二個參數(shù)中給出你自定義的名稱:

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

$this->fubar->function();

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

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

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

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

這個函數(shù)的作用是載入輔助函數(shù), file_name 是輔助函數(shù)對應的文件名,不包括 _helper.php 擴展名。

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

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

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

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

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

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

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

?

翻譯貢獻者: cookieu, Hex, tg8866, weelia, Xwoder, yinzhili
最后修改: 2012-02-06 01:06:30
前の記事: 次の記事: