CakePHP 强制输入 URL

CakePHP Force Typing URLs

好的,我有一个页面名称为 'Contact Us' 的 Web 应用程序。这与所有联系我们的页面一样。输入字段为:姓名、school/company、电子邮件、消息。

因此,一旦用户填写了所有必填信息并单击提交,he/she 将被重定向到一个新页面,该页面只是一条消息,上面写着 "Message sent" 或 "Message sending failed".

假设这是 URL 当用户点击提交按钮时:localhost/appname/controller/messagesent

在其他网站上,如果您尝试键入消息页面的 URL,您应该无法访问它。

所以我希望 'messagesent' 页面仅在单击提交按钮时才可访问。但是,如果由于某种原因用户试图通过在 URL 中键入来访问 'messagesent' 页面,he/she 将被重定向到 index.ctp。

我该怎么做?

谢谢!

编辑:

下面是“联系我们”页面的部分代码:

if($this->Contact->save($data)) { 
                $this->redirect(array('controller' => 'websites', 'action' => 'messagesuccessful'));
            } else{
                    $this->redirect(array('controller' => 'websites', 'action' => 'messagefailed'));
                }

下面是 messagesuccessful() 的代码:

if($this->request->is('post')){
            $this->layout = 'website';
        }else{
            $this->redirect(array('action' => 'index'));
        }

试试这个..

function contactus()
{
    if($this->request->is('post'))
    {
        if($this->Contact->save($data)) { 
            $this->messagesent();
        } else{
                $this->redirect(array('controller' => 'websites', 'action' => 'messagefailed'));
            }
    }
    else{
        // put the code here if you access the function directly (not posting any data)
    }
}

将其设为私有函数,这样任何人都无法直接访问它。

private function messagesent()
{
    $this->render('messagesent', 'website'); 
}

它只是使用 'website' 布局呈现您的消息发送文件。确保将 messagesent.ctp 文件保存在 views 文件夹下的网站文件夹中。

谢谢..!