laravel(4.2) 路由斜杠

个人手记 laravel 路由表 

Route::get('login/',[
   'as' => 'Login',
   'uses' => 'UserController@login'
]);
route("Login");显示不了 http:// xxx.com/login/ 统一显示为 http:// xxx.com/login
查看路由表的代码是trim这个方法,他把结尾的斜杠全部去掉了
总共三个文件修改四处地方,都是去掉trim

Illuminate\Routing\Route.php
  新增
  protected $olduri;
  public function olduri()
  {
	return $this->olduri;
   }
 
 public function __construct($methods, $uri, $action , $olduri)
 {
   	$this->uri = $uri;
	$this->olduri = $olduri;
	$this->methods = (array) $methods;
	$this->action = $this->parseAction($action);

	if (in_array('GET', $this->methods) && ! in_array('HEAD', $this->methods))
	{
		$this->methods[] = 'HEAD';
	}

	if (isset($this->action['prefix']))
	{
		$this->prefix($this->action['prefix']);
	}
}
Illuminate\Routing\Router.php
	protected function createRoute($methods, $uri, $action)
	{
		// If the route is routing to a controller we will parse the route action into
		// an acceptable array format before registering it and creating this route
		// instance itself. We need to build the Closure that will call this out.
		if ($this->routingToController($action))
		{
			$action = $this->getControllerAction($action);
		}

		$route = $this->newRoute(
			$methods,$this->prefix($uri), $action , $uri
		);


		// If we have groups that need to be merged, we will merge them now after this
		// route has already been created and is ready to go. After we're done with
		// the merge we will be ready to return the route back out to the caller.
		if ( ! empty($this->groupStack))
		{
			$this->mergeController($route);
		}


		$this->addWhereClausesToRoute($route);


		return $route;
	}
	
	新增$olduri
protected function newRoute($methods, $uri, $action , $olduri)
{
return new Route($methods, $uri, $action , $olduri);
}
Illuminate\Routing\UrlGenerator.php
protected function replaceRouteParameters($path, array &$parameters)
{
   if (count($parameters))
   {
      $path = preg_replace_sub(
         '/\{.*?\}/', $parameters, $this->replaceNamedParameters($path, $parameters)
      );
   }

   return trim(preg_replace('/\{.*?\?\}/', '', $path), '/');
}
改为
protected function replaceRouteParameters($path, array &$parameters)
{
   if (count($parameters))
   {
      $path = preg_replace_sub(
         '/\{.*?\}/', $parameters, $this->replaceNamedParameters($path, $parameters)
      );
   }
   return preg_replace('/\{.*?\?\}/', '', $path);
}
protected function trimUrl($root, $path, $tail = '')
{
   return trim($root.'/'.trim($path.'/'.$tail, '/'), '/');
}
修改为
protected function trimUrl($root, $path, $tail = '')
{
   
return $root."/".ltrim($path , '/').($tail?'/'.$tail:'');
}
	$route->uri() 修改为 $route->olduri();
	protected function toRoute($route, array $parameters, $absolute)
	{
		$domain = $this->getRouteDomain($route, $parameters);


		$uri = strtr(rawurlencode($this->trimUrl(
			$root = $this->replaceRoot($route, $domain, $parameters),
			$this->replaceRouteParameters($route->olduri(), $parameters)
		)), $this->dontEncode).$this->getRouteQueryString($parameters);


		return $absolute ? $uri : '/'.ltrim(str_replace($root, '', $uri), '/');
	}
欢迎吐槽





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值