Laravel:重定向到另一个需要 POST 变量的控制器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19040099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel: redirect to another controller which requires POST variables
提问by LushSoftware
I have ReportController Index which is routed as POST only
我有 ReportController 索引,它仅作为 POST 路由
public function index() // must have start, end, client
{
$start = Input::get('start'); // <<< This are POST variables
$end = Input::get('end'); // <<< This are POST variables
$client = Input::get('client'); This are POST variables
db request... output view..
}
when I click "delete row", it post info to
当我点击“删除行”时,它会将信息发布到
public function deleteRow()
{
db request -> delete();
//How do I go back to index controller and pass same $_POST['start'],$_POST['end'],$_POST['client']
}
How do I go back to index controller and pass same $_POST['start'],$_POST['end'],$_POST['client']?
如何返回索引控制器并传递相同的 $_POST['start'],$_POST['end'],$_POST['client']?
回答by JofryHS
You might be able to use Redirect::to('url')->withInput()
你也许可以使用 Redirect::to('url')->withInput()
Then you can use Input::get('key')
然后你可以使用 Input::get('key')
If that doesn't work, try Input::old('key')
-> Less pretty
如果这不起作用,请尝试Input::old('key')
-> 不那么漂亮
回答by The Alpha
Your post variables are no longer available once you make another request to the deleteRow
method from the view, so you have to pass those variables to the deleteRow
method. You build a view/ui
from your index
method like
一旦您deleteRow
从视图向该方法发出另一个请求,您的 post 变量将不再可用,因此您必须将这些变量传递给该deleteRow
方法。你view/ui
从你的index
方法构建一个
public function index() // must have start, end, client
{
$start = Input::get('start');
$end = Input::get('end');
$client = Input::get('client');
db request... output view.. // <-- Outputs view with "delete row" link
}
Hope, you pass those post
variables in this view, if not then pass those variables to this view and build the delete row
link with these variables
, something like
希望,您post
在此视图中传递这些变量,如果没有,则将这些变量传递到此视图并delete row
与这些变量建立链接variables
,例如
"ReportController/deleteRow/$start/$end/$client" // just an idea
Which means, your deleteRow
method now should look like (also make changes in the routing of this)
这意味着,您的deleteRow
方法现在应该看起来像(也在此路由中进行更改)
public function deleteRow($start, $end, $client)
{
// db request -> delete();
return Redirect::to('index')
->with('postVars', array('start' => $start, '$end' => $end, 'client', $client));
}
So, it's clear that you have to pass those variables to the deleteRow
method and that's why deleteRow
methods route
should be reconstructed according to the params
. So, finally, your index
method should look like
因此,很明显您必须将这些变量传递给deleteRow
方法,这就是deleteRow
方法route
应该根据params
. 所以,最后,你的index
方法应该看起来像
public function index() // must have start, end, client
{
$postVars = session::has('postVars') ? session::get('postVars') : Input:all();
$start = $postVars['start'];
$end = $postVars['end'];
$client = $postVars['client'];
db request... output view..
}