2017-01-18 25 views
1

定義新的全局變量的文件defines.inc.php包含多個全局變量,但如果我要定義新變量的文件是最好的?凡的Prestashop

如果我更新Prestashop文件define.inc.php重置,我鬆了我的全局變量。

也許在settings.inc.php中,但是這個文件沒有版本。

回答

2

您可以創建config/defines.inc.php旁邊的文件config/defines_custom.inc.php。啓動時Prestashop檢查該文件是否存在。如果它存在,那麼它被包含在默認的之前。

可以在config/config.inc.php找到相關的代碼:

$currentDir = dirname(__FILE__); 

/* Custom defines made by users */ 
if (is_file($currentDir.'/defines_custom.inc.php')) { 
    include_once($currentDir.'/defines_custom.inc.php'); 
} 
require_once($currentDir.'/defines.inc.php'); 

例如,您可以設定的模式開發,沒有碰默認的文件是這樣的:

define('_PS_MODE_DEV_', true); 

而且在默認文件,這個定義將不會發生:

if (!defined('_PS_MODE_DEV_')) { 
    define('_PS_MODE_DEV_', false); 
} 
+0

謝謝你,但在我的版本的PrestaShop不包括(1.6.1.X)這個下面的代碼:include_once($ currentDir '/ defines_custom.inc.php'); –

+2

@alexandrebru然後你必須修改一些東西,因爲它確實存在。 https://github.com/PrestaShop/PrestaShop/blob/1.6.1.x/config/config.inc.php#L30 – TheDrot

+0

@TheDrot是我找到了提交:https://github.com/PrestaShop/PrestaShop/提交/ 146f0676d5e1fc51d7edcdf46b192988ccbe4660 –

0

我建議創建你自己的模塊(也許是一個'dummy'模塊:)),並在那裏聲明你的全局變量。

例如創建一個名爲「MyModule的」模塊,主文件mymodule.php應該是:

// Here you can define your global vars 
define('MY_CUSTOM_VAR', 100); 

class MyModule extends MyModule 
{ 
    public function __construct() 
    { 
     // See documentation 
    } 

    public function install(){ return parent::install(); } 
} 

所以,你可以在不失去你的全局變量問題,更新您的PrestaShop版本;)