首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在我提交POST params on deleting记录后刷新视图

在我提交POST params on deleting记录后刷新视图
EN

Stack Overflow用户
提问于 2013-03-05 16:55:56
回答 1查看 877关注 0票数 0

我的问题是,如何刷新我的视图"search.ctp“,以考虑到我刚刚删除的记录。问题如下。

我的控制器代码

代码语言:javascript
复制
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忘记了我的删除功能代码:

代码语言:javascript
复制
            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'));
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-06 01:23:56

作为一种变通方法,我创建了另一个函数,它对GET请求执行的操作与我的搜索函数对POST请求执行的操作相同。基本上返回带有查询参数的数据。我使用会话帮助器将查询传递给我的其他函数。不知道这有多聪明,但它对我来说很有用……不过,如果有人有解决方案,我不需要创建另一个函数/视图,那就更好了

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15219512

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档