設定設定值
本主題討論可用來執行下列作業的進階組態命令:
- 從命令列設定任何組態選項
- 可選擇鎖定任何設定選項,使其值無法在Admin中變更
- 變更在Admin中鎖定的設定選項
您可以使用這些命令來手動或使用指令碼設定Commerce設定。 您使用 設定路徑,即 /
— 分隔字串,可唯一識別該組態選項。 您可在下列參照中找到組態路徑:
您可以在下列時間設定值:
-
在安裝Commerce之前,您可以僅設定預設範圍的設定值,因為它是唯一的有效範圍。
-
安裝Commerce後,您可以為任何網站或商店檢視範圍設定設定值。
使用下列命令:
bin/magento config:set
依其設定路徑設定任何非敏感設定值bin/magento config:sensitive:set
依其設定路徑設定任何敏感設定值bin/magento config:show
顯示已儲存的組態值;加密設定的值會顯示為星號
必要條件
若要設定組態值,您必須至少知道下列其中一項:
-
設定路徑
-
若要設定特定範圍的組態值,您必須知道範圍代碼。
若要設定預設範圍的設定值,您不需要執行任何動作。
尋找設定路徑
請參閱下列參考資料:
尋找範圍代碼
您可以在Commerce資料庫或Commerce管理員中找到範圍代碼。
若要在Admin中尋找範圍代碼:
-
以可檢視網站和商店檢視的使用者身分登入「管理員」。
-
按一下 Stores >設定> All Stores.
-
在右窗格中,按一下網站或商店檢視的名稱,以檢視其程式碼。
下圖顯示範例網站程式碼。
-
繼續使用 設定值.
在資料庫中尋找範圍代碼:
網站和商店檢視的範圍程式碼會儲存在的Commerce資料庫中 store_website
和 store
表格。
-
連線至Commerce資料庫。
code language-bash mysql -u <Commerce database username> -p
-
輸入下列命令:
code language-shell use <Commerce database name>;
code language-shell SELECT * FROM store;
code language-shell SELECT * FROM store_website;
範例結果如下:
code language-terminal [mysql]> SELECT * FROM store_website; +------------+-------+--------------+------------+------------------+------------+ | website_id | code | name | sort_order | default_group_id | is_default | +------------+-------+--------------+------------+------------------+------------+ | 0 | admin | Admin | 0 | 0 | 0 | | 1 | base | Main Website | 0 | 1 | 1 | | 2 | test1 | Test Website | 0 | 3 | 0 | +------------+-------+--------------+------------+------------------+------------+
使用中的值
code
欄。 -
繼續下一節。
設定值
設定系統特定組態值:
bin/magento config:set [--scope="..."] [--scope-code="..."] [-le | --lock-env] [-lc | --lock-config] path value
設定敏感組態值:
bin/magento config:sensitive:set [--scope="..."] [--scope-code="..."] path value
下表說明 set
命令引數:
--scope
default
, website
,或 store
. 預設值為 default
.--scope-code
-e or --lock-env
<Commerce base dir>/app/etc/env.php
檔案。-c or --lock-config
<Commerce base dir>/app/etc/config.php
檔案。 此 --lock-config
選項覆寫 --lock-env
如果您同時指定兩個選項。path
value
--lock-env
和 --lock-config
選項會取代 --lock
選項。--lock-env
或 --lock-config
選項若要設定或變更值,您必須使用 bin/magento app:config:import
命令 以匯入設定,然後再存取管理員或店面。如果您輸入的設定路徑不正確,這個命令會傳回錯誤
The "wrong/config/path" does not exist
如需詳細資訊,請參閱下列其中一節:
設定可在Admin中編輯的設定值
使用 bin/magento config:set
不含 --lock-env
或 --lock-config
將值寫入資料庫。 您以這種方式設定的值可在Admin中編輯。
設定存放區基底URL的部分範例如下:
設定預設範圍的基底URL:
bin/magento config:set web/unsecure/base_url http://example.com/
設定基礎URL base
網站:
bin/magento config:set --scope=websites --scope-code=base web/unsecure/base_url http://example2.com/
設定基礎URL test
存放區檢視:
bin/magento config:set --scope=stores --scope-code=test web/unsecure/base_url http://example3.com/
設定無法在Admin中編輯的設定值
如果您使用 --lock-env
選項如下,指令會將組態值儲存在 <Commerce base dir>/app/etc/env.php
和停用「管理員」中用於編輯此值的欄位。
bin/magento config:set --lock-env --scope=stores --scope-code=default web/unsecure/base_url http://example3.com
您可以使用 --lock-env
在未安裝Commerce時設定設定值的選項。 不過,您只能設定預設範圍的值。
env.php
檔案是系統專屬的。 您不應該將它轉移到另一個系統。 您可以使用它來覆寫資料庫中的組態值。 例如,您可以從另一個系統取得資料庫傾印並覆寫 base_url
和其他值,因此您不必修改資料庫。如果您使用 --lock-config
選項,組態值會儲存在 <Commerce base dir>/app/etc/config.php
. 在管理員中編輯此值的欄位已停用。
bin/magento config:set --lock-config --scope=stores --scope-code=default web/url/use_store 1
您可以使用 --lock-config
以設定未安裝Commerce時的設定值。 不過,您只能設定預設範圍的值。
config.php
到另一個系統,以在該處使用相同的組態值。 例如,如果您有測試系統,使用相同的 config.php
表示您不必再次設定相同的設定值。顯示組態設定的值
命令選項:
bin/magento config:show [--scope[="..."]] [--scope-code[="..."]] path
位置
--scope
是設定的範圍(預設、網站、商店)。 預設值為default
--scope-code
是設定的範圍代碼(網站代碼或商店檢視代碼)path
是格式為first_part/second_part/third_part/etc (必填)
範例
顯示所有儲存的組態:
bin/magento config:show
結果:
web/unsecure/base_url - http://example.com/
general/region/display_all - 1
general/region/state_required - AT,BR,CA,CH,EE,ES,FI,LT,LV,RO,US
catalog/category/root_id - 2
analytics/subscription/enabled - 1
顯示「 」的所有已儲存組態 base
網站:
bin/magento config:show --scope=websites --scope-code=base
結果:
web/unsecure/base_url - http://example-for-website.com/
general/region/state_required - AT,BR,CA
顯示預設範圍的基底URL:
bin/magento config:show web/unsecure/base_url
結果:
web/unsecure/base_url - http://example.com/
顯示基礎URL base
網站:
bin/magento config:show --scope=websites --scope-code=base web/unsecure/base_url
結果:
web/unsecure/base_url - http://example-for-website.com/
顯示基礎URL default
儲存:
bin/magento config:show --scope=stores --scope-code=default web/unsecure/base_url
結果:
web/unsecure/base_url - http://example-for-store.com/