0

我有 2 个视图文件,比如说file1.ctpfile2.ctp. 我想要什么,当我在 中成功完成某事时file1.ctp,它会向我显示“成功”消息并将我重定向到file2.ctp. 它应该是自动的。

4

2 回答 2

2

您可以在 CakePHP 中使用 render 函数。像这样:

$this->render('file2');

你应该在你的控制器中使用它。

于 2013-10-24T17:48:45.733 回答
2

控制器::闪光灯

从此评论中,您所描述的是Controller::flash

Controller::flash($message, $url, $pause, $layout)

与redirect() 一样,flash() 方法用于在操作后将用户引导至新页面。flash() 方法的不同之处在于它在将用户传递到另一个 URL 之前显示一条消息。

示例用法

考虑 2 个控制器操作,如下所示:

function step1() {
    ...
    $this->flash('Step1 complete, now starting step2', array('action' => 'step2'))
}

function step2() {
    ...
}

访问时/example/step1将执行控制器操作,然后显示带有 text 的普通页面Step1 complete, now starting step2,暂停 1 秒(默认),然后将用户发送到/example/step2使用元刷新

于 2013-10-25T09:07:05.627 回答