我的问题是,如何刷新我的视图"search.ctp“,以考虑到我刚刚删除的记录。问题如下。
我的控制器代码
public function search() {
if ($this->request->is('post')) {
$this->set("isPost", TRUE);
$query = $this->data;
$output = $this->Question->find("all", array("conditions"=>array("Question.lectureId"=>$query["Lecture"]["Lecture"],
"Question.type"=>$query["Lecture"]["status"])));
$this->set("questions", $output);
} else {
$this->LoadModel("Lecture");
$outputL = array();
$for = $this->Lecture->find("all", array("fields" => array("_id", "title")));
foreach ($for as $key => $value) {
$outputL[$value["Lecture"]["_id"]] = $value["Lecture"]["title"];
}
$this->set("lectures",$outputL);
//
$statuses = array(
"" => "Select a question type",
"anonymousQuestion" => "anonymousQuestion",
"handUp" => "handUp",
"userQuestion" => "userQuestion"
);
$this->set("statuses", $statuses);
}
}于是发生了以下事情:我打开视图"search.ctp“("my admin interface"),设置两个搜索参数,然后使用submit按钮发布数据。然后,我的IF语句将其识别为POSt,并返回查询结果。问题是当我删除一条记录..。它将我重定向回我的搜索操作,以再次输入查询参数...如何使用相同的查询参数刷新页面而不离开视图?
O忘记了我的删除功能代码:
public function delete($id = null) {
if (!$this->request->is('post')) {
throw new MethodNotAllowedException();
}
$this->Question->id = $id;
if (!$this->Question->exists()) {
throw new NotFoundException(__('Invalid configuration'));
}
if ($this->Question->delete()) {
$this->Session->setFlash(__('Question deleted'));
return $this->redirect(array("action"=>"search"));
}
$this->Session->setFlash(__('Question was not deleted'));
$this->redirect(array('action' => 'search'));
}发布于 2013-03-06 01:23:56
作为一种变通方法,我创建了另一个函数,它对GET请求执行的操作与我的搜索函数对POST请求执行的操作相同。基本上返回带有查询参数的数据。我使用会话帮助器将查询传递给我的其他函数。不知道这有多聪明,但它对我来说很有用……不过,如果有人有解决方案,我不需要创建另一个函数/视图,那就更好了
https://stackoverflow.com/questions/15219512
复制相似问题