Laravel Blade 如何使用@show 动作打印出uri
Laravel Blade How to print out uri with @show action
在我看来,我想像这样打印一个控制器 uri ShopController@show
。
设置变量$controller = 'ShopControll';
在视图中:
action($controller.'@show',$id)
但是出现了一些错误:
ErrorException in UrlGenerator.php line 603:
Action App\Http\Controllers\ShopController<?php echo $__env->yieldSection(); ?> not defined.
如果像这样:
action('ShopController@show',$id)
有效,输出为:
http://example.com/show/1
所以,有什么区别?
@show 是一个 blade 指令,blade 解析它你想显示这个部分请检查这里示例
@section('sidebar')
This is the master sidebar.
@show
https://laravel.com/docs/5.2/blade#template-inheritance
你可以这样修改你的方法
action($controller,'show',$id)
对于 Laravel >= 5.3 你可以使用 @php @endphp
:
的组合
@php
echo @action($controller.'@show', ['id' => $id])
@endphp
对于早期版本,我认为(仅在 5.3 再次 上测试),这也应该有效:
{{ @action($controller.'@show', ['id' => $id])}}
在我看来,我想像这样打印一个控制器 uri ShopController@show
。
设置变量$controller = 'ShopControll';
在视图中:
action($controller.'@show',$id)
但是出现了一些错误:
ErrorException in UrlGenerator.php line 603:
Action App\Http\Controllers\ShopController<?php echo $__env->yieldSection(); ?> not defined.
如果像这样:
action('ShopController@show',$id)
有效,输出为:
http://example.com/show/1
所以,有什么区别?
@show 是一个 blade 指令,blade 解析它你想显示这个部分请检查这里示例
@section('sidebar')
This is the master sidebar.
@show
https://laravel.com/docs/5.2/blade#template-inheritance
你可以这样修改你的方法
action($controller,'show',$id)
对于 Laravel >= 5.3 你可以使用 @php @endphp
:
@php
echo @action($controller.'@show', ['id' => $id])
@endphp
对于早期版本,我认为(仅在 5.3 再次 上测试),这也应该有效:
{{ @action($controller.'@show', ['id' => $id])}}