Joomla下利用configuration.php存储简单数据

yipeiwu_com5年前PHP代码库
写入过程
复制代码 代码如下:

// Get the path of the configuration file
$fname = JPATH_CONFIGURATION.DS.'configuration.php';
// clear cache
$cache = JFactory::getCache();
$cache->clean();
// Update the credentials with the new settings
$config =& JFactory::getConfig();
$config->setValue('config.custom_var', 'xxx');
// Get the config registry in PHP class format and write it to configuation.php
jimport('joomla.filesystem.file');
if (!JFile::write($fname, $config->toString('PHP', 'config', array('class' => 'JConfig')))) {
die(JText::_('ERRORCONFIGFILE'));
}

提取过程
复制代码 代码如下:

global $mainframe;
$mainframe->getCfg('custom_var');

相关文章

PHP迭代器和生成器用法实例分析

本文实例讲述了PHP迭代器和生成器用法。分享给大家供大家参考,具体如下: 迭代器 迭代器实际是一个实现了Iterator的类,可以用foreach进行遍历。 例如: <?...

PHP 读取文件的正确方法

让我们算一算有多少种方法 处理诸如 PHP 之类的现代编程语言的乐趣之一就是有大量的选项可用。PHP 可以轻松地赢得 Perl 的座右铭“There's more than one wa...

php计算整个目录大小的方法

本文实例讲述了php计算整个目录大小的方法。分享给大家供大家参考。具体实现方法如下: /** * Calculate the full size of a directory *...

PHP实现将浏览历史页面网址保存到cookie的方法

本文实例讲述了PHP实现将浏览历史页面网址保存到cookie的方法。分享给大家供大家参考。具体如下: 将浏览历史页面网址保存到cookie,大致的思路如下面的代码,与实际应用有些差别。...

php 常用类整理

图表库 下面的类库可以让你很简单就能创建复杂的图表和图片。当然,它们需要GD库的支持。 pChart - 一个可以创建统计图的库。 Libchart - 这也是一个简单的统计图库。 Jp...