我有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']?
答案 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..
}