/** * Make data configuration to file options.php inside directory config * * @return mixed */ public function saveAnalyticAction() { $this->view->disable(); //Is not $_POST if (!$this->request->isPost()) { return $this->currentRedirect(); } $filename = ROOT_DIR . 'common/config/options.php'; if (!file_exists($filename)) { $makeFile = ZFunction::makeFile($filename); } if (file_exists($filename)) { $analytic = ['googleAnalytic' => $this->request->getPost('analytic')]; $data = new AdapterPhp($filename); $result = array_merge($data->toArray(), $analytic); $result = '<?php return ' . var_export($result, true) . ';'; if (!file_put_contents($filename, $result)) { throw new \Exception("Data was not saved", 1); } $this->flashSession->success(t('Data was successfully deleted')); return $this->currentRedirect(); } return $this->currentRedirect(); }
public function saveConfig($arrayConfig) { $filename = ROOT_DIR . 'content/options/options.php'; if (!file_exists($filename)) { $makeFile = ZFunction::makeFile($filename); file_put_contents($filename, "<?php return [];"); } if (file_exists($filename)) { $data = new AdapterPhp($filename); $result = array_merge($data->toArray(), $arrayConfig); $result = '<?php return ' . var_export($result, true) . ';'; if (!file_put_contents($filename, $result)) { return false; } return true; } }
/** * 設定ファイルを丸ごと配列で取得 * @return array */ public function getArray() { return $this->config->toArray(); }