| | <?php |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | namespace think; |
| |
|
| | use think\exception\ValidateException; |
| | use traits\controller\Jump; |
| | use think\Log; |
| |
|
| | Loader::import('controller/Jump', TRAIT_PATH, EXT); |
| |
|
| | class Controller |
| | { |
| | use Jump; |
| |
|
| | |
| | |
| | |
| | protected $view; |
| |
|
| | |
| | |
| | |
| | protected $request; |
| |
|
| | |
| | |
| | |
| | protected $failException = false; |
| |
|
| | |
| | |
| | |
| | protected $batchValidate = false; |
| |
|
| | |
| | |
| | |
| | protected $beforeActionList = []; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | public function __construct(Request $request = null) |
| | { |
| | $this->view = View::instance(Config::get('template'), Config::get('view_replace_str')); |
| | $this->request = is_null($request) ? Request::instance() : $request; |
| |
|
| | |
| | $this->_initialize(); |
| |
|
| | |
| | if ($this->beforeActionList) { |
| | foreach ($this->beforeActionList as $method => $options) { |
| | is_numeric($method) ? |
| | $this->beforeAction($options) : |
| | $this->beforeAction($method, $options); |
| | } |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | protected function _initialize() |
| | { |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | protected function beforeAction($method, $options = []) |
| | { |
| | if (isset($options['only'])) { |
| | if (is_string($options['only'])) { |
| | $options['only'] = explode(',', $options['only']); |
| | } |
| |
|
| | if (!in_array($this->request->action(), $options['only'])) { |
| | return; |
| | } |
| | } elseif (isset($options['except'])) { |
| | if (is_string($options['except'])) { |
| | $options['except'] = explode(',', $options['except']); |
| | } |
| |
|
| | if (in_array($this->request->action(), $options['except'])) { |
| | return; |
| | } |
| | } |
| |
|
| | call_user_func([$this, $method]); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | protected function fetch($template = '', $vars = [], $replace = [], $config = []) |
| | { |
| | |
| | if($GLOBALS['config']['site']['new_version'] == 1 || !isset($GLOBALS['config']['site']['new_version']) || (empty($GLOBALS['config']['site']['new_version']) && $GLOBALS['config']['site']['new_version'] != 0)){ |
| | |
| | if (strpos($template, 'admin@') === 0) { |
| | $parts = explode('@', $template); |
| | $result = $parts[1]; |
| | $template = APP_PATH . request()->module() . '/view_new/' . $result . '.html'; |
| | } |
| | } |
| | return $this->view->fetch($template, $vars, $replace, $config); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | protected function display($content = '', $vars = [], $replace = [], $config = []) |
| | { |
| | return $this->view->display($content, $vars, $replace, $config); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | protected function assign($name, $value = '') |
| | { |
| | $this->view->assign($name, $value); |
| |
|
| | return $this; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | protected function engine($engine) |
| | { |
| | $this->view->engine($engine); |
| |
|
| | return $this; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | protected function validateFailException($fail = true) |
| | { |
| | $this->failException = $fail; |
| |
|
| | return $this; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | protected function validate($data, $validate, $message = [], $batch = false, $callback = null) |
| | { |
| | if (is_array($validate)) { |
| | $v = Loader::validate(); |
| | $v->rule($validate); |
| | } else { |
| | |
| | if (strpos($validate, '.')) { |
| | list($validate, $scene) = explode('.', $validate); |
| | } |
| |
|
| | $v = Loader::validate($validate); |
| |
|
| | !empty($scene) && $v->scene($scene); |
| | } |
| |
|
| | |
| | if ($batch || $this->batchValidate) { |
| | $v->batch(true); |
| | } |
| |
|
| | |
| | if (is_array($message)) { |
| | $v->message($message); |
| | } |
| |
|
| | |
| | if ($callback && is_callable($callback)) { |
| | call_user_func_array($callback, [$v, &$data]); |
| | } |
| |
|
| | if (!$v->check($data)) { |
| | if ($this->failException) { |
| | throw new ValidateException($v->getError()); |
| | } |
| |
|
| | return $v->getError(); |
| | } |
| |
|
| | return true; |
| | } |
| | } |
| |
|