redirect(url('/install')); } $configs = \app\common\model\Config::all(); foreach ($configs as $key => &$value) { $this->config[$value->name] = $value->value; } $this->configs = $configs; if (Session::has('uid') && Session::has('token')) { $this->user = Users::get([ 'id' => Session::get('uid'), 'token' => Session::get('token') ]); if (!$this->user) { Session::delete(['uid', 'token']); } } $this->currentStrategyConfig = $this->getStrategyConfig(strtolower($this->config['storage_strategy'])); $this->assign([ 'config' => $this->config, 'user' => $this->user, 'uri' => strtolower($this->request->controller() . '/' . $this->request->action()) ]); } /** * 当前储存策略配置 * * @param $strategy * @return array */ protected function getStrategyConfig($strategy) { $strategyConfig = []; foreach ($this->configs as $value) { if ($value->key === $strategy) { $strategyConfig[$value->name] = $value->value; } } return $strategyConfig; } /** * 获取储存策略驱动实例 * * @param null $strategy * @return mixed */ protected function getStrategyInstance($strategy = null) { $currentStrategy = $strategy ? $strategy : strtolower($this->config['storage_strategy']); // 驱动 $driver = Config::get('strategy.' . $currentStrategy . '.class'); // 获取该储存策略配置 $strategyConfig = $this->getStrategyConfig($currentStrategy); return new $driver($strategyConfig); } protected function sendMail($email, $subject, $body) { $mail = new PHPMailer(); try { // $mail->SMTPDebug = 2; $mail->isSMTP(); $mail->Host = $this->config['mail_smtp_host']; $mail->CharSet = 'UTF-8'; $mail->SMTPAuth = true; $mail->Username = $this->config['mail_smtp_username']; $mail->Password = $this->config['mail_smtp_password']; $mail->SMTPSecure = $this->config['mail_smtp_secure']; $mail->Port = $this->config['mail_smtp_port']; $mail->setFrom($this->config['mail_form_email'], $this->config['site_name']); $mail->addAddress($email); $mail->addReplyTo($this->config['mail_form_email'], $this->config['site_name']); $mail->isHTML(true); $mail->Subject = $subject; $mail->Body = $body; $mail->send(); } catch (Exception $e) { return $this->error($e->getMessage()); } return true; } }