2

我有 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']?

4

2 回答 2

2

一旦您从视图向该方法发出另一个请求,您的 post 变量就不再可用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..

}
于 2013-09-27T00:38:03.183 回答
2

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

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

如果这不起作用,请尝试Input::old('key')-> 不太漂亮

于 2013-09-26T23:18:22.333 回答