Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Config.php
Go to the documentation of this file.
1 <?php
7 
9 
18  \Magento\Framework\App\Config\ConfigResource\ConfigInterface
19 {
25  protected function _construct()
26  {
27  $this->_init('core_config_data', 'config_id');
28  }
29 
39  public function saveConfig($path, $value, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0)
40  {
41  $connection = $this->getConnection();
42  $select = $connection->select()->from(
43  $this->getMainTable()
44  )->where(
45  'path = ?',
46  $path
47  )->where(
48  'scope = ?',
49  $scope
50  )->where(
51  'scope_id = ?',
52  $scopeId
53  );
54  $row = $connection->fetchRow($select);
55 
56  $newData = ['scope' => $scope, 'scope_id' => $scopeId, 'path' => $path, 'value' => $value];
57 
58  if ($row) {
59  $whereCondition = [$this->getIdFieldName() . '=?' => $row[$this->getIdFieldName()]];
60  $connection->update($this->getMainTable(), $newData, $whereCondition);
61  } else {
62  $connection->insert($this->getMainTable(), $newData);
63  }
64  return $this;
65  }
66 
75  public function deleteConfig($path, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0)
76  {
77  $connection = $this->getConnection();
78  $connection->delete(
79  $this->getMainTable(),
80  [
81  $connection->quoteInto('path = ?', $path),
82  $connection->quoteInto('scope = ?', $scope),
83  $connection->quoteInto('scope_id = ?', $scopeId)
84  ]
85  );
86  return $this;
87  }
88 }
saveConfig($path, $value, $scope=ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId=0)
Definition: Config.php:39
$value
Definition: gender.phtml:16
deleteConfig($path, $scope=ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId=0)
Definition: Config.php:75
$connection
Definition: bulk.php:13