"general/region/state_required" 핵심 데이터는 아무것도 반환하지 않습니다!
-
12-12-2019 - |
문제
이게 나를 미치게 만들고 있어!그만큼 general/region/state_required
시스템->구성의 데이터는 다음에서 검색할 수 없습니다. Mage::getStoreConfig()
기능.데이터베이스에는 이 값이 표시되며 데이터 지속성도 정상적으로 작동합니다.CMS의 값을 변경하면 데이터베이스도 변경됩니다.다음은 system.xml
Magento 기본 디렉토리 모듈.
<general>
<groups>
<country>
<fields>
<optional_zip_countries translate="label">
<label>Postal Code is Optional for the following countries</label>
<frontend_type>multiselect</frontend_type>
<sort_order>3</sort_order>
<source_model>adminhtml/system_config_source_country</source_model>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<can_be_empty>1</can_be_empty>
</optional_zip_countries>
</fields>
</country>
<region translate="label">
<label>States Options</label>
<frontend_type>text</frontend_type>
<sort_order>4</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<fields>
<state_required translate="label">
<label>State is required for</label>
<frontend_type>multiselect</frontend_type>
<source_model>adminhtml/system_config_source_country</source_model>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
</state_required>
<display_all translate="label">
<label>Display not required State</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>8</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
</display_all>
</fields>
</region>
</groups>
</general>
사실은, general/region/display_all
비어 있지 않은 값이 있으면 null도 반환합니다.이건 정말 이상해요. 지금은 전혀 모르겠어요. 누구든지 도와주실 수 있나요?!
--업데이트--
이 값이 어딘가에서 재정의될 가능성이 있습니까?일부 코드에서 이 값을 null로 하드코딩하는 것처럼 이는 db의 값을 재정의합니다.
아래에 제안된 몇 가지 방법을 시도했지만 불행히도 여기에서는 문제가 해결되지 않습니다.사람들로부터 더 많은 의견이 있나요?
해결책
Alan Storm의 내부 내용을 다루는 기사 시리즈가 있습니다. Mage::getStoreConfig()
널리:
- http://alanstorm.com/magento_config_tutorial
- http://alanstorm.com/magento_config_declared_modules_tutorial
- http://alanstorm.com/magento_loading_config_variables
즉, 값은 다음에서 올 수 있습니다.
default
,config/websites
그리고config/stores
XML 파일의 노드app/etc
(app/etc/modules에 있을 수도 있지만 그럴 가능성은 거의 없습니다)default
,config/websites
그리고config/stores
모든 모듈의 노드config.xml
core_config_data
테이블default
,config/websites
그리고config/stores
노드app/etc/local.xml
구성은 이 순서대로 로드되어 각 단계의 기존 값을 재정의합니다(예:local.xml의 우선순위가 가장 높습니다)
구성 값을 어디에도 저장하지 않고 구성 모델에서 런타임에 설정할 수도 있습니다.검색 중 Mage::getConfig()
지역 코드 풀에서 찾는 데 도움이 될 수 있습니다.
다른 팁
저는 이 정확한 문제를 발견하고 해결 방법을 알아냈습니다.
핵심 구성 데이터가 내부 데이터베이스에서 로드되는 경우 app/code/core/Mage/Core/Model/Resource/Config.php
90번 라인에서
// load all configuration records from database, which are not inherited
$select = $read->select()
->from($this->getMainTable(), array('scope', 'scope_id', 'path', 'value'));
if (!is_null($condition)) {
$select->where($condition);
}
$rowset = $read->fetchAll($select);
// set default config values from database
foreach ($rowset as $r) {
if ($r['scope'] !== 'default') {
continue;
}
$value = str_replace($substFrom, $substTo, $r['value']);
$xmlConfig->setNode('default/' . $r['path'], $value);
}
모든 데이터는 다음에서 가져옵니다. core_config_data
xml 구조에 저장됩니다.데이터는 다음과 같은 순서로 로드됩니다. config_id
, 그래서 일어난 일은 빈 기본값이 설정되어 있고 테이블 끝 부분에 다음과 같이 있는 것입니다.
공지사항 ID 2203.경로는 다음과 같이 설정됩니다. general
그리고 그 값은 NULL
!
Magento가 내부에서 ID 2203을 처리할 때 lib/Varien/Simplexml/Config.php
548행에서:
public function setNode($path, $value, $overwrite=true)
{
$xml = $this->_xml->setNode($path, $value, $overwrite);
return $this;
}
그만큼 NULL
기본 경로 값은 xml 객체 내부의 값을 지웁니다.
어떻게 이런일이 일어 났습니까?
글쎄요, Magento 내부를 더 자세히 살펴보고 core_config_data
테이블이 생성되었습니다.
CREATE TABLE `{$installer->getTable('core_config_data')}` (
`config_id` int(10) unsigned NOT NULL auto_increment,
`scope` enum('default','websites','stores','config') NOT NULL default 'default',
`scope_id` int(11) NOT NULL default '0',
`path` varchar(255) NOT NULL default 'general',
`value` text NOT NULL,
PRIMARY KEY (`config_id`),
UNIQUE KEY `config_scope` (`scope`,`scope_id`,`path`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
따라서 기본적으로 Magento는 기본 경로를 다음으로 설정합니다. default
, 기본 범위_ID는 다음과 같습니다. 0
, 그러나 주의할 점은 value
~이다 NULL이 되어서는 안 됩니다..그렇다면 Magento는 어떻게 NULL
값?
간단해요. 누군가/뭔가 이런 짓을 했어요 Mage::getConfig()->saveConfig('general');
직접 사용해 보고 확인해 보세요.작동할 것이고 Magento는 NULL
테이블의 값.작동 이유를 이해하고 싶다면 내부를 살펴보세요. app/code/core/Mage/Core/Model/Config.php
라인 1535:
public function saveConfig($path, $value, $scope = 'default', $scopeId = 0)
{
$resource = $this->getResourceModel();
$resource->saveConfig(rtrim($path, '/'), $value, $scope, $scopeId);
return $this;
}
그리고 내부 app/code/core/Mage/Core/Model/Resource/Config.php
184행에서:
public function saveConfig($path, $value, $scope, $scopeId)
{
$writeAdapter = $this->_getWriteAdapter();
$select = $writeAdapter->select()
->from($this->getMainTable())
->where('path = ?', $path)
->where('scope = ?', $scope)
->where('scope_id = ?', $scopeId);
$row = $writeAdapter->fetchRow($select);
$newData = array(
'scope' => $scope,
'scope_id' => $scopeId,
'path' => $path,
'value' => $value
);
if ($row) {
$whereCondition = array($this->getIdFieldName() . '=?' => $row[$this->getIdFieldName()]);
$writeAdapter->update($this->getMainTable(), $newData, $whereCondition);
} else {
$writeAdapter->insert($this->getMainTable(), $newData);
}
return $this;
}
TL;DR;해결책다음 SQL 쿼리를 실행하세요.
SELECT * FROM magento.core_config_data WHERE value IS NULL;
행을 삭제하고 path
=== default
그리고 value IS NULL
(참고용으로 내 스크린샷을 참조하세요).
DELETE FROM core_config_data WHERE scope = 'default' AND scope_id = 0 AND path = 'general' AND value IS NULL;
다음 중 하나를 사용하여 저장소를 명시적으로 설정한 후 구성을 쿼리할 수 있습니다.
$config = Mage::getStoreConfig('inchoo/inchoo_group/inchoo_input', Mage::app()->getStore());
또는
Mage::app()->setCurrentStore(0);
$config = Mage::getStoreConfig('general/region/state_required');
구성을 명시적으로 다시 로드한 다음 다음을 사용하여 값을 로드할 수도 있습니다.
Mage::app()->getConfig()->reinit();
Mage::getStoreConfig('inchoo/inchoo_group/inchoo_input', Mage::app()->getStore());