Example #1
0
 /**
  * 返回401
  * 可以根据实际情况在项目内覆盖
  *
  * @return void
  */
 public function redirectTo401()
 {
     if (IS_AJAX) {
         exit(Response::send_http_status(401));
     } else {
         Redirect::error(Lang::get('_ERROR_401'), Url::make($this->loginPage));
     }
 }
Example #2
0
File: Jump.php Project: GDdark/cici
 /**
  * 操作错误跳转的快捷方法
  * @access protected
  * @param mixed $msg 提示信息
  * @param string $url 跳转的URL地址
  * @param mixed $data 返回的数据
  * @param integer $wait 跳转等待时间
  * @return void
  */
 protected function error($msg = '', $url = null, $data = '', $wait = 3)
 {
     $code = 0;
     if (is_numeric($msg)) {
         $code = $msg;
         $msg = '';
     }
     if (is_null($url)) {
         $url = 'javascript:history.back(-1);';
     } else {
         $url = preg_match('/^(https?:|\\/)/', $url) ? $url : Url::build($url);
     }
     $result = ['code' => $code, 'msg' => $msg, 'data' => $data, 'url' => $url, 'wait' => $wait];
     $type = $this->getResponseType();
     if ('html' == strtolower($type)) {
         $result = ViewTemplate::instance(Config::get('template'), Config::get('view_replace_str'))->fetch(Config::get('dispatch_error_tmpl'), $result);
     }
     $response = Response::create($result, $type);
     throw new HttpResponseException($response);
 }
Example #3
0
function U($url, $vars = '', $suffix = true, $domain = false)
{
    return \think\Url::build($url, $vars, $suffix, $domain);
}
Example #4
0
 /**
  * Url生成
  * @param string        $url 路由地址
  * @param string|array  $vars 变量
  * @param bool|string   $suffix 生成的URL后缀
  * @param bool|string   $domain 域名
  * @return string
  */
 function url($url = '', $vars = '', $suffix = true, $domain = false)
 {
     return Url::build($url, $vars, $suffix, $domain);
 }
Example #5
0
 public function testRoot()
 {
     Config::set('url_domain_deploy', false);
     Config::set('url_common_param', false);
     Url::root('/index.php');
     Route::get('blog/:id', 'index/blog/read');
     Config::set('url_html_suffix', 'shtml');
     $this->assertEquals('/index.php/blog/10/name/thinkphp.shtml', Url::build('index/blog/read?id=10&name=thinkphp'));
 }
Example #6
0
 /**
  * 获取跳转地址
  * @return string
  */
 public function getTargetUrl()
 {
     return strpos($this->data, '://') || 0 === strpos($this->data, '/') ? $this->data : Url::build($this->data, $this->params);
 }
Example #7
0
 /**
  * URL重定向
  * @access protected
  * @param string $url 跳转的URL表达式
  * @param array $params 其它URL参数
  * @return void
  */
 public static function redirect($url, $params = [])
 {
     $url = Url::build($url, $params);
     header('Location: ' . $url);
 }
Example #8
0
 /**
  * 获取跳转地址
  * @return string
  */
 public function getTargetUrl()
 {
     return preg_match('/^(https?:|\\/)/', $this->data) ? $this->data : Url::build($this->data, $this->params);
 }
Example #9
0
 /**
  * URL重定向
  * @access public
  * @param string $url 跳转的URL表达式
  * @param array|int $params 其它URL参数或http code
  * @return void
  */
 public function redirect($url, $params = [])
 {
     $http_response_code = 301;
     if (is_int($params) && in_array($params, [301, 302])) {
         $http_response_code = $params;
         $params = [];
     }
     $url = preg_match('/^(https?:|\\/)/', $url) ? $url : Url::build($url, $params);
     header('Location: ' . $url, true, $http_response_code);
 }
Example #10
0
 public function post_edit()
 {
     $data = $this->model->create();
     $this->model->save($data);
     Redirect::success('编辑成功', Url::make('index', $this->query));
 }
Example #11
0
 private function ResponseCreate($code, $msg, $data, $url, $wait, $header)
 {
     if (!empty($url)) {
         $url = preg_match('/^(https?:|\\/)/', $url) ? $url : Url::build($url);
     }
     $result = ['code' => $code, 'msg' => $msg, 'data' => $data, 'url' => $url, 'wait' => $wait];
     $type = $this->getResponseType();
     if ('html' == strtolower($type)) {
         $result = $this->fetch(Config::get('dispatch_success_tmpl'), $result);
     }
     return Response::create($result, $type)->header($header);
 }
Example #12
0
 public function testBuildAnchor()
 {
     Route::get('blog/:id', 'index/blog');
     Config::set('url_html_suffix', 'shtml');
     $this->assertEquals('/blog/10.shtml#detail', Url::build('/blog/10#detail'));
 }
Example #13
0
    public function testUrl()
    {
        $template = new template();
        $content = <<<EOF
{url link="Index/index"  /}
EOF;
        $template->display($content);
        $this->expectOutputString(\think\Url::build('Index/index'));
    }
Example #14
0
/**
 * URL组装 支持不同URL模式
 *
 * @param string $url URL表达式,格式:'[分组/模块/操作#锚点@域名]?参数1=值1&参数2=值2...'
 * @param string|array $vars 传入的参数,支持数组和字符串
 * @param string $suffix 伪静态后缀,默认为true表示获取配置值
 * @param boolean $redirect 是否跳转,如果设置为true则表示跳转到该URL地址
 * @param boolean $domain 是否显示域名
 *
 * @return string
 */
function U($url = '', $vars = '', $suffix = true, $domain = false)
{
    return Url::make($url, $vars, $suffix, $domain);
}