简体   繁体   中英

Kohana 3.3 config files

Respective All!

How can I store Kohana configuration files (email, auth, pagination) in MySQL database?

Any help would be very appreciated.

After some exercises I solved this.

Step 1: Create table (code from Kohana source

/modules/database/classes/Kohana/Config/Database\Writer.php`)

CREATE TABLE IF NOT EXISTS config (
   group_name varchar(128) NOT NULL,
   config_key varchar(128) NOT NULL,
   config_value text,
   PRIMARY KEY (group_name,config_key)
) ENGINE=InnoDB;

Step 2: Put in bootstrap (I added after modules section):

Database::instance();
Kohana::$config->attach(new Kohana_Config_Database, FALSE);

Step 3: Use standard method to put serializable values into the table

Kohana::$config->_write_config('mymodule','options','Hard_to_solve')

Step 4: Use standard way to get it back

Kohana::$config->load('mymodule')->get('options')

What you are clearly describing is simply accessing a database. If there are some configuration options you want to store in a database so that your app or web app can retrieve them, you simply need to look at how Kohana accesses databases. Start by looking in the application/bootstrap.php and uncomment the database module (also uncomment userguide). You'll then need to copy the modules/database/config/database.php to your config folder and setup the access. If you uncommented the userguide, just go to http://yourdomain.com/guide (replace "yourdomain" with your actual domain name) and there is a whole description of how to setup kohana for database access all the way through to making queries. Have fun!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM