CodeIgnitor 配置類的使用

2022-02-04 02:37:54 字數 1409 閱讀 3529

<?php

$config['uri_protocol'] = 'request_uri';

// ...

$config['charset'] = 'utf-8';

// ...

$config['subclass_prefix'] = 'my_';

可以看到所有的配置資訊都放在$config陣列裡。框架缺省會載入這個配置檔案,所以使用時直接用item()呼叫:

<?php

$this->config->item('uri_protocol'); // 'request_uri'

<?php

$config['index_page'] = 'welcome';

使用時,需要先載入custom.php檔案,然後獲取配置內容:

<?php

$this->config->load('custom');

$index_page = $this->config->item('index_page'); // 'welcome'

當載入多個配置檔案時,這些配置檔案中的$config會合併,所以如果在不同的配置檔案中如果有相同的鍵的話,就會產生衝突(先載入的配置會被後載入的配置覆蓋)。這可以通過指定load()的第二個引數來解決。

假設現在有兩個配置檔案:custom1.phpcustom2.php,它們的內容如下:

// custom1.php

$config['index_page'] = 'welcome1';

// custom2.php

$config['index_page'] = 'welcome2';

在載入時指定load()第二個引數為 true,來分別儲存配置項的值到不同的陣列中(而不是原來的的$config):

$this->config->load('custom1.php', true);

$this->config->load('custom2.php', true);

然後在獲取配置項時,在item()第二個引數指定配置檔名就可以正確獲取到配置項了:

$this->config->item('index_page', 'custom1'); // 'welcome1'

$this->config->item('index_page', 'custom2'); // 'welcome2'

MongoDB的配置類

configuration configuration註解表明這個類是乙個配置類。可以啟動元件掃瞄,用來將帶有 bean的實體進行例項化bean等。configuration可理解為用spring的時候xml裡面的標籤,作用為 配置spring容器 應用上下文 bean可理解為用spring的時候x...

Extjs定義類的配置項

定義乙個類 ext.define person constructor function config statics 定義類的配置項,屬性不能被子類繼承 statics 而inheritablestatics 與static類似,但是屬性可以被子類繼承 inheritablestatics ext...

方便的讀取配置項類

本文的目的是分享乙個好用的,可用於大型專案中讀取配置項的類configfilereader,包含了一系列的讀寫配置項,載入配置項檔案等相關操作,可直接拿來使用。需要的人拿走。具體 如下,貼在這裡方便閱讀,源 可以到我的github上獲取 cconfigfilereader 類用於讀取配置檔案中的各個...