如何在Laravel中创建相对路径URL?

I need to use relative paths for my site (Lets just say for reasons I don't want to get into it has to be relative).

Currently I'm using the following in my site:

# url to controller
{{  Form::open(array('url' => 'users/signin') }}

# url to controller
 <li><a href="{{action('UsersController@getLogout')}}" class="navbar-brand "> <span class=""></span> Logout </a></li>

# url to style
{{ HTML::style('css/main.css')}}

I've tried others too but all of them constructs absolute URLs such as:

http://localhost:8888/mysite/users/logout

In vanilla PHP i could place relative paths like this:

<li><a href="../search/">Search</a></li>

I abandoned HTML::style() and used relative URLs on my css,js etc. like this which works:

<link rel="stylesheet" type="text/css" href="/css/main.css">

However how can do this for links to controller methods?

php
dongyan3616
dongyan3616 你是对的。
6 年多之前 回复
dongpengyu1363
dongpengyu1363 关于说你在CSS和Javascript上使用相对URL:/css/main.css是绝对URI。绝对URI以正斜杠开头。无论您使用哪种URI层次结构,它们都会导致请求相同的页面。我想你想要摆脱主持人;即URI之前的位?
6 年多之前 回复

1个回答



看起来这对Laravel 4来说是不可能的。我确实找到了某人修改了Laravel中的URL类允许这样做,但它确实意味着您正在使用第三方代码来实现其他集成功能 。</ p>
</ div>

展开原文

原文

It seems like this isn't possible out-of-the-box with Laravel 4. I did find someone's modification of the URL class in Laravel which allows this, but it does mean you are using third-party code for otherwise integrated functionality.

douzai8285
douzai8285 谢谢。 你用过这个吗? 你是否创建了包dir并将文件放在其中?
6 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐