BaseInstall.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\install\controller;
  3. use core\base\BaseController;
  4. use think\App;
  5. use think\facade\View;
  6. class BaseInstall extends BaseController
  7. {
  8. public $replace = [];
  9. public $lock_file;
  10. public $lang;
  11. public $install_root = '';
  12. public function __construct(App $app)
  13. {
  14. parent::__construct($app);
  15. $this->lock_file = '../install.lock';//锁定文件
  16. $root_url = request()->domain();
  17. View::assign("root_url", $root_url);
  18. $this->setInstallRoot();
  19. }
  20. /**
  21. * 加载模板输出
  22. * @access protected
  23. * @param string $template 模板文件名
  24. * @param array $vars 模板输出变量
  25. * @return string
  26. */
  27. protected function fetch($template = '', $vars = [])
  28. {
  29. return View::fetch($template, $vars);
  30. }
  31. /**
  32. * 模板变量赋值
  33. * @access protected
  34. * @param mixed $name 要显示的模板变量
  35. * @param mixed $value 变量的值
  36. * @return void
  37. */
  38. protected function assign($name, $value = '')
  39. {
  40. View::assign($name, $value);
  41. }
  42. public function setInstallRoot()
  43. {
  44. $this->install_root = dirname(__DIR__) . '/';
  45. }
  46. public function str_replace_first($search, $replace, $subject)
  47. {
  48. return implode($replace, explode($search, $subject, 2));
  49. }
  50. public function checkLock()
  51. {
  52. if (file_exists($this->lock_file)) {
  53. header("location:/index.php");
  54. exit;
  55. }
  56. }
  57. }