2014-07-03 28 views
1

如何更改core_config_data表中使用安裝腳本的值?使用安裝腳本Magento core_config_data行更新

+0

爲什麼你會想做的事是什麼?而是給出完整的情況,並且可能有更好的方法來解決這個問題。 – anz

+0

我也對此感興趣,適應這種情況的主要原因是分段/和本地開發環境。每當我將生產數據庫引入分段時,我總是必須手動更改網頁/安全網頁/不安全的網址。 – Rob

回答

1

是,可以使用下面的代碼

$Switch = new Mage_Core_Model_Config(); 
/* 
*turns notice on 
*/ 
$oSwitch ->saveConfig('web/unsecure/base_url', "http://127.0.0.1/magento1702/", 'default', 0); 
/* 
*turns notice off 
*/ 
$switch ->saveConfig('web/secure/base_url', "http://127.0.0.1/magento1702/", 'default', 0); 
+0

謝謝你的回答!這對我有用阿米特!是Rob,我希望這樣做的主要原因是切換到分段並且不想手動更改core_config_data表中的數據。 – maya89

0

您可以使用Magento的方式,而不是自定義代碼做到這一點。 例如:

$valueToInsert = 'Custom url, or another value'; 
$installer = $this; 
$installer->startSetup(); 

$installer->getConnection() 
    ->update($this->getTable('core_config_data'), 
     array('value' => $valueToInsert), 
     $installer->getConnection()->quoteInto('path=?', 'web/secure/base_url') 
    ); 

$installer->endSetup(); 

更新的第一參數()函數是表名,第二個是數組「列名」 =>「您的值」,並且最後一個參數是WHERE子句。在這種情況下,我們使用函數quoteInto()中的準備語句。爲更新() finction 更多細節,你可以在瓦瑞恩/ DB /適配器/ Interface.php找到