示例#1
0
 public function testPathHelper()
 {
     set_app($app = new Application());
     $app['request'] = Request::create('http://www.foo.com', 'GET');
     $this->assertEquals('http://www.foo.com/bar', path('bar'));
     $this->assertEquals('https://www.foo.com/bar', path('bar', array(), true));
     $this->assertEquals('https://www.foo.com/bar', secure_path('bar'));
 }
示例#2
0
文件: functions.php 项目: lkmmmj/iphp
function base_path()
{
    static $path = false;
    if ($path === false) {
        $uri = $_SERVER['REQUEST_URI'];
        if (($pos = strpos($uri, '?')) !== false) {
            $uri = substr($uri, 0, $pos);
        }
        $uri = secure_path($uri);
        /*
        if(preg_match('/^(.*)\/(\d+)$/', $uri, $ms)){
        	$uri = $ms[1] . '/view';
        	$_GET['id'] = $ms[2];
        }
        */
        // URL rewrite
        $ps = explode('/', $uri);
        if ($ps[count($ps) - 1] == 'index') {
            unset($ps[count($ps) - 1]);
        }
        $np = count($ps);
        if (preg_match('/^\\d+$/', $ps[$np - 1])) {
            $_GET['id'] = $ps[$np - 1];
            $ps[$np - 1] = 'view';
        } else {
            if ($np >= 2 && preg_match('/^\\d+$/', $ps[$np - 2])) {
                $_GET['id'] = $ps[$np - 2];
                $act = $ps[$np - 1];
                $ps = array_slice($ps, 0, -2);
                $ps[] = $act;
            }
        }
        $uri = join('/', $ps);
        $basepath = dirname($_SERVER['SCRIPT_NAME']);
        $path = substr($uri, strlen($basepath));
        $path = trim(trim($path), '/');
    }
    return $path;
}