gpt4 book ai didi

php - 防止直接访问 Action Controller

转载 作者:行者123 更新时间:2023-12-04 05:57:48 25 4
gpt4 key购买 nike

我正在使用 zend 框架。在一个 View 中,我使用了一个 Action 助手。
echo $this->action('info', 'comment', null, array('articleID' => $article->arti_id));
因此,助手调用“CommentController”类和方法“infoAction”。在我的方法中,我得到了“articleID”参数,然后我开始处理模型。最后我呈现一个共享 View 。

public function infoAction() {
$articleID = $this->getRequest()->getParam('articleID');
// Working with model
// .....
$this->renderScript('/View/Script/DefaultComment.phtml');
}

它运行良好,但我不希望此 Controller /操作可通过 url domain.com/comment/info 直接访问.

我怎样才能避免这种情况?

谢谢

最佳答案

如果您的操作方法总是使用文章 id 参数调用,那么您可以在没有 id 的情况下重定向请求:

public function infoAction() {
if ($this->_hasParam('articleID')) {
$articleID = $this->getRequest()->getParam('articleID');
// Working with model
// .....
$this->renderScript('/View/Script/DefaultComment.phtml');
} else {
$this->_helper->redirector('index', 'index', 'default');
}
}

关于php - 防止直接访问 Action Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9310025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com