douyalin2258 2017-03-16 09:33
浏览 47

如何在joomla中通过数据库修改模板参数

I want to modify the current template params via database outside joomla framework. I managed to set the 'preset' param, but I can't write it back to the database. Here is my code.

Thanks a lot

// Initialize The Joomla Framework
// -----------------------------------------------------------------------------------
define('_JEXEC', 1);

// this is relative to the current script, so change this according to your environment
define('JPATH_BASE', '/home/kristof/public_html/joomla1'); 
define('DS', DIRECTORY_SEPARATOR);

// Require Joomla libraries
require_once(JPATH_BASE . DS . 'includes' . DS . 'defines.php');
require_once(JPATH_BASE . DS . 'includes' . DS . 'framework.php');
require_once(JPATH_CONFIGURATION . DS . 'configuration.php');
require_once(JPATH_LIBRARIES . DS . 'joomla' . DS . 'database' . DS . 'database.php');
require_once(JPATH_LIBRARIES . DS . 'import.php');
// -----------------------------------------------------------------------------------

$app = JFactory::getApplication('site');
$template = $app->getTemplate(true);
$param=$template->params->set('preset','preset3');
  • 写回答

1条回答 默认 最新

  • dqdes60666 2018-08-06 18:51
    关注
    $template = JFactory::getApplication('site')->getTemplate();
        $db = JFactory::getDBO();
        $sql = "select params from #__template_styles where template = ".$db->quote($template);
        $db->setQuery($sql);
        $params = json_decode($db->loadResult());
        $params->PARAM_NAME= PARAM_VALUE;
    
        $sql = "update #__template_styles set params = ".$db->quote(json_encode($params))." where template = ".$db->quote($template);
        $db->setQuery($sql);
        return $db->query();
    
    评论

报告相同问题?