Laravel:重定向到需要POST变量的另一个控制器

时间:2013-09-26 23:01:48

标签: laravel laravel-4

我有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..

}

当我点击“删除行”时,它会将信息发布到

public function deleteRow()
{
    db request -> delete();
    //How do I go back to index controller and pass same $_POST['start'],$_POST['end'],$_POST['client']
}

如何返回索引控制器并传递相同的$ _POST ['start'],$ _ POST ['end'],$ _ POST ['client']?

2 个答案:

答案 0 :(得分:2)

您可以使用Redirect::to('url')->withInput()

然后您可以使用Input::get('key')

如果不起作用,请尝试Input::old('key') - &gt;不太好看

答案 1 :(得分:2)

从视图中对deleteRow方法发出另一个请求后,您的帖子变量将不再可用,因此您必须将这些变量传递给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
}

希望您在此视图中传递这些post变量,如果没有,则将这些变量传递到此视图,并使用这些delete row构建variables链接,例如

"ReportController/deleteRow/$start/$end/$client" // just an idea

这意味着,您的deleteRow方法现在应该是这样的(也会更改此路由)

public function deleteRow($start, $end, $client)
{
    // db request -> delete();
    return Redirect::to('index')
    ->with('postVars', array('start' => $start, '$end' => $end, 'client', $client));
}

因此,很明显您必须将这些变量传递给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..

}