gpt4 book ai didi

php - CakePHP Auth 允许 JSON 扩展

转载 作者:搜寻专家 更新时间:2023-10-31 20:53:41 25 4
gpt4 key购买 nike

基本上,我想知道的是您是否可以使用 Auth 组件来允许某些扩展(JSON/HTML)?

基本上,假设我们有一个 Action , Action 是索引。在此操作中,我们所做的只是列出作者(用户)。所以网址是http://somewebsite.com/authors/index .如果我们转到该 url,内容类型将是 HTML,这应该仅限于登录用户(管理员),以便他们可以拥有编辑/删除按钮。但是,当您将 .json 扩展名放在它的末尾时,我们也使用此操作来呈现 json,因此 url 将为 http://somewebsite.com/authors/index.json .在这种情况下,您不需要登录,因为您只想访问该信息。

那么,Auth Component 是否可以允许某些扩展,这是最好的方法吗?

谢谢和干杯!

最佳答案

按照这些思路应该可以工作(包括明确地“解锁”特定方法):

public function beforeFilter() {
$methods = array('index', 'foo', 'bar');

// please forgive the terrible indentation
if (in_array($this->action, $methods) &&
isset($this->params['ext']) && $this->params['ext'] == 'json'
) {
$this->Auth->allow($this->action);
}
}

关于php - CakePHP Auth 允许 JSON 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4866738/

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