【问题标题】:Gibberish route output乱码路由输出
【发布时间】:2016-12-16 19:02:59
【问题描述】:

我为编辑帖子创建了链接,但输出看起来很乱

href="http://web.app/admin/blog/post/post_id%20=%3E%20%24post_id/edit

应该是什么时候

href="http://web.app/admin/blog/post/2/edit

网址

<a href="{{ route('admin.blog.post.edit', ['post_id => $post_id']) }}">Edit</a>

路线

Route::get('/blog/post/{post_id}/edit', [
    'uses'  => 'PostController@getUpdatePost',
    'as'    => 'admin.blog.post.edit'
]);

【问题讨论】:

  • 你有一个错误的报价:['post_id' =&gt; $post_id]
  • 如果你对链接进行 URL 解码,你会得到 http://web.app/admin/blog/post/post_id =&gt; $post_id/edit 这基本上是说你的路由的 post_id 参数是 post_id =&gt; $post_id 。这应该表明问题所在。

标签: php laravel laravel-5 laravel-routing


【解决方案1】:

改变

<a href="{{ route('admin.blog.post.edit', ['post_id => $post_id']) }}">Edit</a>

<a href="{{ route('admin.blog.post.edit', ['post_id' => $post_id]) }}">Edit</a>

你只是把引号放错了地方。如果你有正确的语法高亮,这很容易发现,所以如果你还没有的话,我强烈建议你为你的 IDE 或文本编辑器安装一个刀片语法高亮器。

【讨论】:

  • 感谢它的帮助,这是我的拼写错误
  • 但是对于我使用 {{ route('admin.index') }} 的同一个例子,结果就像web.app/%7B%7B%20route('admin.index')%20%7D%7D 我是 laravel 的新手,我不知道我错过了什么
  • 如果您有其他问题,请提出一个新问题,这超出了本问题的范围。
【解决方案2】:

替换

{{ route('admin.blog.post.edit', ['post_id => $post_id']) }}

{! route('admin.blog.post.edit', ['post_id => $post_id']) !}

{{}} 表示它将按原样回显

同时

{!!} 表示会被处理,而 route() 需要这个

【讨论】:

  • 首先,{! !} 不会逃逸,{!! !!} 会逃逸。二、route()不输出任何HTML,它输出一个URL,不需要转义。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-13
  • 1970-01-01
  • 2010-12-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多