domain() public static method

注册子域名部署规则
public static domain ( string | array $domain, mixed $rule = '', array $option = [], array $pattern = [] ) : void
$domain string | array 子域名
$rule mixed 路由规则
$option array 路由参数
$pattern array 变量规则
return void
Esempio n. 1
0
 public function testBuildDomain()
 {
     Config::set('url_domain_deploy', true);
     Route::domain('subdomain.thinkphp.cn', 'admin');
     $this->assertEquals('http://subdomain.thinkphp.cn/blog/10.shtml', Url::build('/blog/10'));
     Route::domain('subdomain.thinkphp.cn', ['hello/:name' => 'index/hello']);
     $this->assertEquals('http://subdomain.thinkphp.cn/hello/thinkphp.shtml', Url::build('index/hello?name=thinkphp'));
 }
Esempio n. 2
0
 public function testDomain()
 {
     $request = Request::create('http://subdomain.thinkphp.cn');
     Route::domain('subdomain.thinkphp.cn', 'sub?abc=test&status=1');
     $rules = Route::rules('GET');
     Route::checkDomain($request, $rules);
     $this->assertEquals('sub', Route::getbind('module'));
     $this->assertEquals('test', $_GET['abc']);
     $this->assertEquals(1, $_GET['status']);
     Route::domain('subdomain.thinkphp.cn', '\\app\\index\\controller');
     $rules = Route::rules('GET');
     Route::checkDomain($request, $rules);
     $this->assertEquals('\\app\\index\\controller', Route::getbind('namespace'));
     Route::domain(['subdomain.thinkphp.cn' => '@\\app\\index\\controller\\blog']);
     $rules = Route::rules('GET');
     Route::checkDomain($request, $rules);
     $this->assertEquals('\\app\\index\\controller\\blog', Route::getbind('class'));
 }
Esempio n. 3
0
 public function testDomain()
 {
     $_SERVER['HTTP_HOST'] = 'subdomain.thinkphp.cn';
     $_SERVER['REQUEST_URI'] = '';
     Route::domain('subdomain.thinkphp.cn', 'sub?abc=test&status=1');
     Route::checkDomain();
     $this->assertEquals('sub?abc=test&status=1', Route::domain('subdomain.thinkphp.cn'));
     $this->assertEquals('sub', Route::bind('module'));
     $this->assertEquals('test', $_GET['abc']);
     $this->assertEquals(1, $_GET['status']);
     Route::domain('subdomain.thinkphp.cn', function () {
         return ['type' => 'module', 'module' => 'sub2'];
     });
     Route::checkDomain();
     $this->assertEquals('sub2', Route::bind('module'));
     Route::domain('subdomain.thinkphp.cn', '\\app\\index\\controller');
     Route::checkDomain();
     $this->assertEquals('\\app\\index\\controller', Route::bind('namespace'));
     Route::domain('subdomain.thinkphp.cn', '@\\app\\index\\controller\\blog');
     Route::checkDomain();
     $this->assertEquals('\\app\\index\\controller\\blog', Route::bind('class'));
     Route::domain('subdomain.thinkphp.cn', '[sub3]');
     Route::checkDomain();
     $this->assertEquals('sub3', Route::bind('group'));
 }