Load database config file from libraries in CodeIg
Sometime you will want to load database config variables from your libraries.In this case, if you use $this-_CI-config-load(database) , you will get an error: $this-_CI = get_instance();$this-_CI-config-load('database'); The error somthing
Sometime you will want to load database config variables from your libraries.In this case, if you use $this->_CI->config->load(‘database’), you will get an error:
$this->_CI = &get_instance(); $this->_CI->config->load('database');
The error somthing like Your application/config/database.php file does not appear to contain a valid configuration array.
The source is in `system/core/Config.php#138`:
// CodeIgniter Version 2.1.4 if ( ! isset($config) OR ! is_array($config)) { if ($fail_gracefully === TRUE) { return FALSE; } show_error('Your '.$file_path.' file does not appear to contain a valid configuration array.'); }
You can find that the config will lookup an array with the name $config, but in your database’s config file it contains array variable with the name $db?defaultly.This is the reason you got the invalid configuration array error message.
To correctly load database configuration from libraries,you can you code below:
$this->_CI->load->database('default'); $db = $this->_CI->db; Something::config(['driver'=> 'mysql','host'=> $db->hostname, 'dbname'=> $db->database, 'user'=> $db->username, 'password'=> $db->password]);
Notice the `default` is the active group in your database configuration file.
原文地址:Load database config file from libraries in CodeIg, 感谢原作者分享。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

メモ帳++7.3.1
使いやすく無料のコードエディター

mPDF
mPDF は、UTF-8 でエンコードされた HTML から PDF ファイルを生成できる PHP ライブラリです。オリジナルの作者である Ian Back は、Web サイトから「オンザフライ」で PDF ファイルを出力し、さまざまな言語を処理するために mPDF を作成しました。 HTML2FPDF などのオリジナルのスクリプトよりも遅く、Unicode フォントを使用すると生成されるファイルが大きくなりますが、CSS スタイルなどをサポートし、多くの機能強化が施されています。 RTL (アラビア語とヘブライ語) や CJK (中国語、日本語、韓国語) を含むほぼすべての言語をサポートします。ネストされたブロックレベル要素 (P、DIV など) をサポートします。

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

ドリームウィーバー CS6
ビジュアル Web 開発ツール
