From ab1a2450869ff6e27e0bebf0bf2a79092775b962 Mon Sep 17 00:00:00 2001 From: nate Date: Wed, 6 Feb 2008 20:47:48 +0000 Subject: [PATCH] Adding option to remove application base path to Router::url() git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6444 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/router.php | 6 +++++- cake/tests/cases/libs/router.test.php | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cake/libs/router.php b/cake/libs/router.php index 36619c1b6..dffad95d0 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -670,10 +670,14 @@ class Router extends Object { $path = end($_this->__paths); } } - $base = $path['base']; // dont need this anymore $_this->stripPlugin($path['base'], $params['plugin']); + $base = $path['base']; $extension = $output = $mapped = $q = $frag = null; if (is_array($url) && !empty($url)) { + if (array_key_exists('base', $url) && $url['base'] === false) { + $base = null; + unset($url['base']); + } if (isset($url['full_base']) && $url['full_base'] == true) { $full = true; unset($url['full_base']); diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index a763e5d6b..12e2eba14 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -864,6 +864,26 @@ class RouterTest extends UnitTestCase { $this->assertEqual($result, $expected); } + function testRemoveBase() { + $this->router->reload(); + $this->router->setRequestInfo(array( + array('controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'bare' => 0, 'webservices' => null, 'plugin' => null), + array('base' => '/base', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array(), 'webservices' => null) + )); + + $result = $this->router->url(array('controller' => 'my_controller', 'action' => 'my_action')); + $expected = '/base/my_controller/my_action/'; + $this->assertEqual($result, $expected); + + $result = $this->router->url(array('controller' => 'my_controller', 'action' => 'my_action', 'base' => false)); + $expected = '/my_controller/my_action/'; + $this->assertEqual($result, $expected); + + $result = $this->router->url(array('controller' => 'my_controller', 'action' => 'my_action', 'base' => true)); + $expected = '/base/my_controller/my_action/base:1'; + $this->assertEqual($result, $expected); + } + function testParamsUrlParsing() { $this->router->reload(); $this->router->connect('/', array('controller' => 'posts', 'action' => 'index'));