2017-09-30 5 views
2

PHPを使ってJoomla 3.xのconfiguration.phpファイルに値を設定したいと思っています。私のようなものを持つ値を簡単に十分に得ることができますphomを使ってjoomla設定ファイルを更新する

$config = new JConfig(); 
$dbprefix = $config->dbprefix; 

私が検索したが、値を設定するのいずれかの方法を見つけることができません。私はjoomlaそれが可能なので、それを前提としています。私は全体のファイルを読み込み、検索と置換にPHPを使用することができますが、私はJoomlaがそれを行うことができるようにセッターや同様のAPIを持っていることを望んでいる。

私は検索と検索が、私は

ヘルプを見つけることができるものは何もありませんしました!

TA

私も今JConfigにセッターを追加しようとしたが、それは動作していないようでした!

public function setTestvar($testvar) { 
    $this->ftp_user = $testvar; 
} 

答えて

1

残念ながら私はJoomla! GitHubのソースコードを簡単に見て、に何をしたいのかを調べる機能がいくつかありますが、これはJoomla\Registry\Registryというインスタンスになります。

このクラスは、私はあなたがJoomlaの最近のバージョンを使用していると仮定していたファイルadministrator/components/com_config/model/application.php

で定義されています!私はこのようにYMMVをテストしていません。

ここで問題になっている方法です。

/** 
* Method to write the configuration to a file. 
* 
* @param Registry $config A Registry object containing all global config data. 
* 
* @return boolean True on success, false on failure. 
* 
* @since 2.5.4 
* @throws RuntimeException 
*/ 
private function writeConfigFile(Registry $config) 
{ 
    jimport('joomla.filesystem.path'); 
    jimport('joomla.filesystem.file'); 

    // Set the configuration file path. 
    $file = JPATH_CONFIGURATION . '/configuration.php'; 

    // Get the new FTP credentials. 
    $ftp = JClientHelper::getCredentials('ftp', true); 

    $app = JFactory::getApplication(); 

    // Attempt to make the file writeable if using FTP. 
    if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0644')) 
    { 
     $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTWRITABLE'), 'notice'); 
    } 

    // Attempt to write the configuration file as a PHP class named JConfig. 
    $configuration = $config->toString('PHP', array('class' => 'JConfig', 'closingtag' => false)); 

    if (!JFile::write($file, $configuration)) 
    { 
     throw new RuntimeException(JText::_('COM_CONFIG_ERROR_WRITE_FAILED')); 
    } 

    // Attempt to make the file unwriteable if using FTP. 
    if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0444')) 
    { 
     $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTUNWRITABLE'), 'notice'); 
    } 

    return true; 
} 

・ホープ、このことができます:)

は、
関連する問題