In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the example analysis of Setting enhanced configuration class in CI, which is very detailed and has certain reference value. Friends who are interested must read it!
The details are as follows:
This enhanced configuration class is suitable for projects where configuration items require more flexibility. Can achieve pre-loading configuration, group configuration, individual call, add, delete, change configuration, no need to change the config document.
Use:
Where you need it.
$this- > load- > library ('setting')
For preadd-ins, you can use the
$this- > config- > item ()
To obtain
For temporary recall items, you can use the
$this- > setting- > item ()
To obtain
First, create a data table
CREATE TABLE `system_ settings` (`id`int (11) unsigned NOT NULL AUTO_INCREMENT, `key`varchar (64) NOT NULL DEFAULT', `value` mediumtext NOT NULL, `group`varchar (55) NOT NULL DEFAULT 'site', `autoload` enum (' no','yes') NOT NULL DEFAULT 'yes', PRIMARY KEY (`id`, `key`), KEY `name` (`key`), KEY `autoload` (`autoload`) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8
Then, create a setting.php under the application/libraries directory, as follows
* * / public function item ($key) {if (! $key) {return FALSE;} / / first check whether the system has automatically loaded if (isset ($this- > settings [$key]) {return $this- > settings [$key];} / / query the database $this- > _ ci- > db- > select ('value')-> from ($this- > settings_db)-> where (' key', $key) $query = $this- > _ ci- > db- > get (); if ($query- > num_rows () > 0) {$row = $query- > row (); $this- > settings [$key] = $row- > value; return $row- > value;} / / find system config if no result is found, or false return $this- > _ ci- > config- > item ($key) } / /-/ * get group configuration * / public function group ($group ='') {if (! $group) {return FALSE } $this- > _ ci- > db- > select ('key,value')-> from ($this- > settings_db)-> where (' group', $group); $query = $this- > _ ci- > db- > get (); if ($query- > num_rows () = = 0) {return FALSE;} foreach ($query- > result () as $k = > $row) {$this- > settings [$row- > key] = $row- > value; $arr [$row- > key] = $row- > value } return $arr;} / /-/ * change settings * / public function edit ($key, $value) {$this- > _ ci- > db- > where ('key', $key) $this- > _ ci- > db- > update ($this- > settings_db, array ('value' = > $value)); if ($this- > _ ci- > db- > affected_rows () = 0) {return FALSE;} return TRUE } / /-/ * New settings * / public function insert ($key, $value ='', $group = 'addon' $autoload = 'no') {/ / check whether the settings $this- > _ ci- > db- > select (' value')-> from ($this- > settings_db)-> where ('key', $key) have been added $query = $this- > _ ci- > db- > get (); if ($query- > num_rows () > 0) {return $this- > edit ($key, $value);} $data = array ('key' = > $key,' value' = > $value, 'group' = > $group,' autoload' = > $autoload,); $this- > _ ci- > db- > insert ($this- > settings_db, $data) If ($this- > _ ci- > db- > affected_rows () = = 0) {return FALSE;} return TRUE } / /-/ * Delete settings * / public function delete ($key) {$this- > _ ci- > db- > delete ($this- > settings_db, array ('key' = > $key)) If ($this- > _ ci- > db- > affected_rows () = = 0) {return FALSE;} return TRUE } / /-/ * Delete settings group and member configuration * / public function delete_group ($group) {$this- > _ ci- > db- > delete ($this- > settings_db) Array ('group' = > $group)) If ($this- > _ ci- > db- > affected_rows () = = 0) {return FALSE;} return TRUE;}} / * End of file Setting.php * / * Location:. / application/libraries/Setting.php * /
Finally, open application/config/config.php and add
/ * system configuration table name * / $config ['settings_table'] = "system_settings"; the above is all the contents of the article "sample Analysis of Setting enhanced configuration classes in CI". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.