mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Use App.base when there are no requests to generate URL's
Setting App.fullBaseUrl to a non-host value causes issues generating URL's in a web context. However, not including the base path generates incorrect URL's in a CLI context. This change allows the use of App.base to populate the base path which is used as a fallback when there are no requests, or when the base path is empty. Refs #2931
This commit is contained in:
parent
5aa8a458b1
commit
4265dbcc33
2 changed files with 15 additions and 0 deletions
|
@ -803,6 +803,9 @@ class Router {
|
||||||
$params = $request->params;
|
$params = $request->params;
|
||||||
$path = array('base' => $request->base, 'here' => $request->here);
|
$path = array('base' => $request->base, 'here' => $request->here);
|
||||||
}
|
}
|
||||||
|
if (empty($path['base'])) {
|
||||||
|
$path['base'] = Configure::read('App.base');
|
||||||
|
}
|
||||||
|
|
||||||
$base = $path['base'];
|
$base = $path['base'];
|
||||||
$extension = $output = $q = $frag = null;
|
$extension = $output = $q = $frag = null;
|
||||||
|
|
|
@ -80,6 +80,18 @@ class RouterTest extends CakeTestCase {
|
||||||
$this->assertEquals('https://example.com', Configure::read('App.fullBaseUrl'));
|
$this->assertEquals('https://example.com', Configure::read('App.fullBaseUrl'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that Router uses App.base to build URL's when there are no stored
|
||||||
|
* request objects.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testBaseUrlWithBasePath() {
|
||||||
|
Configure::write('App.base', '/cakephp');
|
||||||
|
Router::fullBaseUrl('http://example.com');
|
||||||
|
$this->assertEquals('http://example.com/cakephp/tasks', Router::url('/tasks', true));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testRouteDefaultParams method
|
* testRouteDefaultParams method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue