不知道TP有没有这个功能,自己做了一个可以把配置参数保存到数据库,Thinkphp 3.2放到
/项目目录/Common/Common/function.php里就可以使用了。function CD($key, $value = null){<br>
<br>
/**<br>
* 公共方法,可以把配置参数保存到数据库<br>
*<br>
* 用法:<br>
* CD('配置项'); //读取配置项<br>
* CD('配置项', '数据') //写入配置项<br>
* CD('配置项', 'DEL') //从数据库中移除该配置项<br>
*<br>
*<br>
*在数据库中建立config表,表前缀改成自己的<br>
* CREATE TABLE IF NOT EXISTS `think_config` (<br>
* `id` int(11) NOT NULL AUTO_INCREMENT,<br>
* `key` varchar(255) CHARACTER SET utf8 NOT NULL,<br>
* `value` varchar(255) CHARACTER SET utf8 NOT NULL,<br>
* PRIMARY KEY (`id`)<br>
* ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;<br>
*/<br>
<br>
$cd = M('Config');<br>
$where = array( 'key' => $key);<br>
<br>
//如果有$value为空,就返回$key的值<br>
if($value == null){<br>
return $cd->where( $where )->getField('value');<br>
}<br>
//如果$value为DEL,就删除这条记录的值<br>
else if($value == "DEL")<br>
{<br>
return $cd->where( $where )->delete();<br>
}<br>
//如果$value有正常值,其它操作<br>
else{<br>
<br>
//如果存在$key,更新<br>
if($cd->where($where)->find()){<br>
$cd->value = $value;<br>
return $cd->where($where)->save();<br>
}<br>
//如果不存在$key,写入一条新数据<br>
else{<br>
$cd->key = $key;<br>
$cd->value = $value;<br>
return $cd->add();<br>
}<br>
}<br>
}
AD:真正免费,域名+虚机+企业邮箱=0元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

WebStorm Mac version
Useful JavaScript development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool