douben6670 2014-07-04 23:39
浏览 273

如何在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?

  • 写回答

1条回答 默认 最新

  • dongsun5330 2014-07-05 00:01
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Labview机器人问题
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示