0

我的问题是如何刷新我的视图“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”(“我的管理界面”),设置 2 个搜索参数,然后使用提交按钮发布该数据。然后我的 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'));
}
4

1 回答 1

1

作为一种解决方法,我创建了另一个函数,它对 GET 请求执行与我的搜索函数对 POST 请求执行相同的操作。基本上返回带有查询参数的数据。我使用 Session 助手将查询传递给我的其他函数。不知道那有多聪明,但它对我有用......仍然很高兴知道是否有人有一个解决方案,我不必制作另一个功能/视图

于 2013-03-05T17:23:56.337 回答