Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用按钮onclick重定向_Php_Laravel - Fatal编程技术网

Php 使用按钮onclick重定向

Php 使用按钮onclick重定向,php,laravel,Php,Laravel,我使用的是Laravel框架和刀片模板引擎 我想做的是,在我的视图中有两个按钮,当单击时,会将您重定向到另一个视图。我尝试的代码是: <button type="button" onclick="{{ Redirect::to('users.index') }}">Button</button> 按钮 您可以尝试此操作(假设刀片模板中有此代码): 这意味着,您有一个如下所示的路由声明: Route::get('users/index', array('uses' =&

我使用的是Laravel框架和刀片模板引擎

我想做的是,在我的视图中有两个按钮,当单击时,会将您重定向到另一个视图。我尝试的代码是:

 <button type="button" onclick="{{ Redirect::to('users.index') }}">Button</button>
按钮
您可以尝试此操作(假设刀片模板中有此代码):

这意味着,您有一个如下所示的路由声明:

Route::get('users/index', array('uses' => 'UserController@index', 'as' => 'users.index'));
在这种情况下,也可以使用:

<button type="button" onclick="window.location='{{ route("users.index") }}'">Button</button>
按钮

输出将是相同的。

是的,您基本上需要使用URL帮助程序来生成URL(与只放置类似的内容而不是PHP帮助程序相同):

按钮
虽然我不明白为什么不能使用“a href”标记而不是按钮,如下所示:

<a href="{{ URL::route('users.index'); }}">My button</a>

<button type="button" onclick="window.location='{{ route("users.index") }}'">Button</button>
<button type="button" onclick="window.location='{{ URL::route('users.index'); }}'">Button</button>
<a href="{{ URL::route('users.index'); }}">My button</a>